Upload file using Ajax call using ASP.NET MVC

Total Post:183


 3005  View(s)
Rate this:

I would like to upload a file in my page using:

<input type="file" name="FileName">

I have a button, clicking on which an ajax post is done.


           cache: false,

           async: true,

           type: "POST",

           url: '@Url.Content("~/OCR/OCRProcessor")',

           data: '',

           success: function (data) {




I would like to get the file uploaded in the controller action method something like below:

HttpPostedFileBase hpf = Request.Files["FileName"] as HttpPostedFileBase

Please let me know the optimal way to achieve this task.

  1. Re: Upload file using Ajax call using ASP.NET MVC

    Hi Ankita,

    $('#myFormId').submit(function() {

        // submit the form


        // return false to prevent normal browser submit and page navigation

        return false;



    This would be a No plugin approach (only in Html5), but I'm still recommending the plugin


        var formData = new FormData($(this)[0]);


            url: "YourPath/ToAction",

            type: 'POST',

            data: formData,

            async: false,

            success: function (data) {



            cache: false,

            contentType: false,

            processData: false


        return false;



Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.