Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a form with a file input that works fine with HTML form. When I submit the form, I can grab my value in the file input; but when AJAX is used, the file input field is always null.

THIS WORKS

@using (Html.BeginForm("ProcessSubmit", "Upload",
                     FormMethod.Post, new { id = "uploadForm", enctype =   "multipart/form-data" })) { 
    @(Html.Telerik().Upload().Name("attachments"))
    <p class="note">
    Maximum combined file size: 10 MB
   </p>
   <div style="margin: 20px 0 0 0;">
       <input type="submit" value="Send" class="t-button" />
       <input type="reset" value="Reset" class="t-button" />
   </div>
}    

and the controller: 
[HttpPost]
    public ActionResult ProcessSubmit(IEnumerable<HttpPostedFileBase> attachments)
    {
        if (attachments != null)
        {
            return Content("is not null");
        }
        return Content("null");
    }

But this does not work

@using (Ajax.BeginForm("ProcessSubmit", "Upload",
                     new AjaxOptions { UpdateTargetId = "mydiv" })) { 
     <div id="mydiv"></div>
    @(Html.Telerik().Upload().Name("attachments"))
    <p class="note">
    Maximum combined file size: 10 MB
   </p>
   <div style="margin: 20px 0 0 0;">
       <input type="submit" value="Send" class="t-button" />
       <input type="reset" value="Reset" class="t-button" />
   </div>
}  

In the former, the controller always returns "is not null" while in the latter it always returns null. :(

What is up with this please?

share|improve this question
1  
This isn't a direct answer to your question, and I don't know your requirements but might I recommend taking a look at FineUpload? I'm not affiliated with them in any regard but I have recently switched to using it in an MVC app that used to use Telerik's MVC Extensions and it was stupid simple to get working. – Yarx Feb 27 at 21:33
I'm not sure what the Telerik file upload helper is using, but it's not possible to do an ajax file upload. To work around this most people use an iframe to mimic an asynchronous upload. stackoverflow.com/questions/543926/… – ptfaulkner Feb 27 at 22:31

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.