0

I had a Ajax.BeginForm to do a upload of a file.It´s all right except when I debug my controller the parameter HttpPostedFileBase postedFile is null.

 <div class="form-group">
            <input type="file" class="form-control" name="postedFile" id="postedFile" />
            <input type="submit" value="Import" />
        </div>
 public JsonResult UploadFile(HttpPostedFileBase postedFile)

My Ajax.BeginForm

@using (Ajax.BeginForm("UploadFile", "Ponto", new AjaxOptions
{
    HttpMethod = "POST",
    OnSuccess = "OnSuccess",
    OnFailure = "OnFailure",
    LoadingElementId = "progress"
    
}, new { enctype = "multipart/form-data" }))

the has the same name on parameter controller.

  • No, it does not have the same name as the controller parameter. `file` is not the same thing as `postedFile`. –  Dec 28 '17 at 14:32
  • I realized that when I got rid works perfectly, but don´t show up the loader. – lorranpalmeira Dec 28 '17 at 16:53
  • You cannot upload files using `Ajax.BeginForm()`. Use `jQuery.ajax()` with `FormData`. –  Dec 28 '17 at 21:31
  • Refer [this answer](https://stackoverflow.com/questions/31768946/required-field-validations-not-working-in-jquery-popup-mvc-4/31769058#31769058) for an example –  Dec 28 '17 at 21:35

0 Answers0