Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MVC 5 Ajax BeginForm File Upload No File?

Posted on 2014-07-24
4
Medium Priority
?
6,610 Views
Last Modified: 2014-07-25
Q. What am I missing that stops this Ajax.BeginForm from uploading a file to the controller action?

1. I always receive a null on the Action 'files'...
2. Unsure if Jquery v. 1.11.1 is an issue

[View] 
  <div id="ProfileFileUpload">
      @{ Html.RenderPartial("_FileUpload"); }
  </div>

[PartialView]
@Scripts.Render("~/bundles/jquery")
@using (Ajax.BeginForm("Upload", "MyAccount", null, new AjaxOptions {  HttpMethod = "POST", UpdateTargetId = "ProfileFileUpload" }, new { enctype = "multipart/form-data"}))
{   
    <input type="file" id="file" name="files" />
    <br>
    <input type="submit" id="submit" value="Upload Image" />                            
}


  [Action]
  [HttpPost]
  public ActionResult Upload(IEnumerable<HttpPostedFileBase> files) 
  {
       foreach (var file in files)
       {
            if (file != null && file.ContentLength > 0)
            {
             }
        }
     return PartialView("_FileUpload"); 
  }

[View Source]
<script src="/Scripts/jquery-1.11.1.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

<form action="/MyAccount/Upload" data-ajax="true" data-ajax-method="POST" data-ajax-mode="replace" data-ajax-update="#FileUpload" enctype="multipart/form-data" id="form0" method="post">    

    <input type="file" id="file" name="files" />
    <br>
    <input type="submit" id="submit" value="Upload Image" />                            
</form>

Open in new window

0
Comment
Question by:WorknHardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 1900 total points
ID: 40217723
I tried running your code and it works fine i.e. I can see value in the file.
I tested in IE10 and FF.

Not sure what could be causing that...
0
 

Author Comment

by:WorknHardr
ID: 40219251
Q. What Jquery version are you using?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 40219875
I tried 1.10.2 and 1.11.1. You can try switching the jquery version on your file and see if that makes any difference for you.
0
 

Author Closing Comment

by:WorknHardr
ID: 40219884
Thanks for testing the code. I really appreciate it, thx...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question