0

I am working on MVC. I have a form to send Email. The razor form is below

@Ajax.BeginForm("sendEmail", "communication", new AjaxOptions() { OnBegin = "return onBeginFun();", UpdateTargetId = "emailMessage" }, new { id = "communicationForm", enctype = "multipart/form-data" })
{
   @Html.TextAreaFor(m => m._Email.Body, new { @class = "form-control editor overflow:scroll; max-height:300px", name = "emailbody", id = "emailbody" })

   <input type="file" id="fileUploader" name="fileUploader" multiple ;" />
  <button type="submit" id="submitCommunication"> SAVE>>></button>
}

The controller is as follows

[HttpPost]
    [ValidateInput(false)]
    public async Task<JsonResult> sendEmail(CommunicationModelView P_CMV, HttpPostedFileBase fileUploader)
    {

....................
}

Upon clicking submit button I can see the Model filled with the form data, but fileUploader is null even though I have selected file(s).

Need help. Thanks in advance.

user3513192
  • 97
  • 2
  • 14
  • Remove the string ` multiple ;" ` at the end of the file tge – D-Shih Mar 17 '18 at 23:03
  • I removed the 'multiple' , but not avail – user3513192 Mar 17 '18 at 23:07
  • 2
    You cannot use `@Ajax.BeginForm()` to upload files. If you want to use ajax, then use `FormData` - refer [How to append whole set of model to formdata and obtain it in MVC](https://stackoverflow.com/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc/29293681#29293681) for an example –  Mar 17 '18 at 23:57

0 Answers0