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 869251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:16:42+00:00 2026-05-15T10:16:42+00:00

I have a file upload button on my MVC view. After the file is

  • 0

I have a file upload button on my MVC view. After the file is uploaded, my FileList partial view on the page should refresh.

I tried to upload with Ajax.BeginForm(), but have discovered that Ajax will not submit file data.

I’ve got the file upload working now by using the jQuery Form plugin, which lets you ajaxify the normal Html.BeginForm() submit method.

Is is still possible to trigger the partial page update using this method?

  • 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-05-15T10:16:43+00:00Added an answer on May 15, 2026 at 10:16 am

    Yeah you could use the success option in the .ajaxForm to pass back data from the file upload and then pass that data to the PartialView or just refresh the partial.

         // Setup the from plugin
        $('#formId').ajaxForm(
                              success: function(data) { UploadSuccess(data); },
                              dataType: 'json', 
                              iframe:true);
        $('#formId').submit();
    
        // Success callback fundtion
        function UploadSuccess(data)
        {
            // You can then access any data in the JSON object and pass it in the route to the partial
            $('#divId').load('/FileList/' + data.FileName);
        }
    
    // Original HTML of partial
    <div id="divId">
        <%Html.RenderPartial("FileList");%>
    </div>
    
            // Action to handle upload
            public FileUploadJSONResult Upload()
            {
                FileUploadJSONResult result;
    
                try
                {
                    if (Request.Files.Count > 0)
                    {
                        //  Logic to save file goes here
    
                        result = new FileUploadJSONResult()
                        {
                            Data = new
                            {
                                FileName = "Test filename",
                                ErrorMessage = string.Empty
                            }
                        };
                    }
                    else
                    {
                        result = new FileUploadJSONResult
                        {
                            Data = new
                            {
                                FileName = string.Empty,
                                LogicalName = string.Empty,
                                ErrorMessage = "No file to upload. Please select a file to upload."
                            }
                        };
                    }
                }
                catch (Exception e)
                {
                    Exception root = e;
                    while ((root.InnerException) != null)
                    {
                        root = root.InnerException;
                    }
    
                    result = new FileUploadJSONResult
                    {
                        Data = new
                        {
                            FileName = string.Empty,
                            LogicalName = string.Empty,
                            ErrorMessage = root.Message
                        }
                    };
                }
    
                return result;
            }
    
    // Then needed to wrap the JSON result due to the iframe textarea issue with this plugin
    public class FileUploadJSONResult : JsonResult
        {  
            /// <summary>
            /// The following explanation of this code is from http://www.malsup.com/jquery/form:
            /// 
            ///  Since it is not possible to upload files using the browser's XMLHttpRequest object, the Form Plugin 
            ///  uses a hidden iframe element to help with the task. This is a common 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, 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. Please note, however, that if a file has not been selected by the user for the 
            ///  file input 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. 
            /// </summary>
            /// <param name="context">Controller context</param>
            public override void ExecuteResult(ControllerContext context)
            {
                this.ContentType = "text/html";
                context.HttpContext.Response.Write("<textarea>");
                base.ExecuteResult(context);
                context.HttpContext.Response.Write("</textarea>");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file upload function in my asp.net mvc application that allows users
I have a file upload page with an AsyncFileUpload control. When the user browses
I have a file upload control <input id=File1 type=file /> in my page... How
I want to have file upload possibilites on my MVC site, and I have
I have a file Upload control and I have a button Upload ., so
I have a file upload form that is being posted back to a servlet
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have a form that excepts a file upload in ASP.NET. I need to
I have a .NET webform that has a file upload control that is tied
I have a web application that needs to take a file upload from the

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.