Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7927573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:22:43+00:00 2026-06-03T19:22:43+00:00

So I have ajax file upload partial (using Jquery Form plugin), it’s working perfectly,

  • 0

So I have ajax file upload partial (using Jquery Form plugin), it’s working perfectly, but I don’t know to update model value after file uploading

<div>
   @Html.Partial("PhotoUpload", Model.Place)
</div>

Here I’m calling partial and giving to it part of a model.

@model PlaceMap.DAL.Entities.Place
@using (Html.BeginForm("PhotoUpload", "Place", FormMethod.Post, new { @id = "photoUpload", enctype = "multipart/form-data" }))
{
    {
        @Html.ValidationSummary(true, "Image upload was unsuccessful")
        @Html.HiddenFor(m => m.Photo)                                                                                                                                                                                  
        <input type="file" id="file" name="file"/>
        <input type="submit" id="sbm" />
    }
}

This is view code of partial, accepting model and form for uploading

var options = {
    url: "/Place/PhotoUpload",
    dataType: "json",
    clearForm: true,
    resetForm: true,
    success: showResponse
};

function showResponse(responseText, statusText, xhr, $form)
{
    $('#photo').append('<img src="/Images/Places/' + responseText.Photo + '" />');
}

$('#photoUpload').submit(function ()
{
    $('#photoUpload').ajaxSubmit(options);
    return false;
});

Javascript code for plugin

    [Authorize]
    [HttpPost]
    public ActionResult PhotoUpload(string Photo, HttpPostedFileBase file)
    {
        try
        {
            using (var ms = new MemoryStream())
            {
                //some logic here
                return Json(new { Photo = filename });
            }

        }
        catch (ArgumentException)
        {

        }

        return PartialView();
    }

Controller action code. It’s returning file name, it’s going to js function “showResponse” and appending image to div. It’s all work perfectly, but I have to write file name to @Model.Photo of this partial and I don’t know how to do it. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:22:45+00:00Added an answer on June 3, 2026 at 7:22 pm

    One possibility is to use text/plain from the server:

    return Json(new { Photo = filename }, "text/plain");
    

    and on the client manually parse:

    function showResponse(responseText, statusText, xhr, $form) {
        var data = $.parseJSON(responseText);
        $('#photo').append('<img src="/Images/Places/' + data.Photo + '" />');
    }
    

    Obviously you lust remove the dataType: 'json' option for this to work.

    Another possibility is to follow what’s explained in the documentation and write a custom action result which will wrap your JSON response with the <textarea> tags:

    Browsers that support the XMLHttpRequest Level 2 will be able to
    upload files seamlessly and even get progress updates as the upload
    proceeds. For older browsers, a fallback technology is used which
    involves iframes since it is not possible to upload files using the
    level 1 implmenentation of the XMLHttpRequest object. This is a common
    fallback technique, but it has inherent limitations. The iframe
    element is used as the target of the form’s submit operation which
    means that the server response is written to the iframe. This is fine
    if the response type is HTML or XML, but doesn’t work as well if the
    response type is script or JSON, both of which often contain
    characters that need to be repesented using entity references when
    found in HTML markup.

    To account for the challenges of script and JSON responses when using
    the iframe mode, the Form Plugin allows these responses to be embedded
    in a textarea element and it is recommended that you do so for these
    response types when used in conjuction with file uploads and older
    browsers. Please note, however, that if there is no file input in the
    form then the request uses normal XHR to submit the form (not an
    iframe). This puts the burden on your server code to know when to use
    a textarea and when not to. If you like, you can use the iframe option
    of the plugin to force it to always use an iframe mode and then your
    server can always embed the response in a textarea. But the
    recommended solution is to test for the ‘X-Requested-With’ request
    header. If the value of that header is ‘XMLHttpRequest’ then you know
    that the form was posted via ajax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Jquery form plugin to upload file in Ajax request.File is successfully
I am using Jquery form plugin to upload file in Ajax request.File is successfully
I have an Ajax contact form that links to a jquery file but for
I have a working Ajax form, now I'm trying to add file upload to
i need to upload file with jquery. i now about uploadify plugin, but i
I'm using a flash/ajax file upload in php based on this site - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/
i have 3 problems (!) using a mighty simple file-upload-form. i will try to
I have read that ajax fileupload is not possible. But I want to upload
I'm using this jquery plugin ajaxFileupload in our project. My design is I have
I have an ajax.php file in my Wordpress themes folder, and this was working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.