If I don't refer jquery.unobtrusive-ajax.js I can get attachment on Post. If I refer it It's giving me null.
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
@using (Ajax.BeginForm("Index", "ContactSubmission", new AjaxOptions{ InsertionMode = InsertionMode.Replace, HttpMethod = "POST", OnSuccess = "updateSuccess" },
new { enctype = "multipart/form-data",@class = "form-horizontal", role = "form" }))
{
///code here
}
[HttpPost]
public JsonResult Index(Contact contact)
{
if (ModelState.IsValid)
{
if (contact != null)
{
string attachment = string.Empty;
// HttpPostedFileBase Attachment
if (contact.Attachment != null) attachment = SaveFile(contact.Attachment);
......
How to handle this?
If you don't refer
jquery.unobtrusive-ajax.js, you don't get theajaxform, but a regular HTML form. And if you do, I suppose the form works fine, but it is not possible to upload a file with it, as ajax does not allowmultipart/form-dataenctype.You can use HTML 5 File API (Using files from web applications) or jQuery upload plugins.