I am getting 'null' value for HttpPostedBaseFile in controller.I am calling the Action method using jquery through Json.
View code
@using (Html.BeginForm("SaveAlertList", "AlertListUpload", new { enctype = "multipart/form-data" }, FormMethod.Post, new { id = "formUpload" }))
{
@Html.ValidationSummary(null, new {@class = "validation-summary formErrors ui-state-error invisible"})
<div class="table-container">
<div class="table-container-row">
<div class="table-container-cell">
<fieldset>
<legend id="importlegend"><b>Import</b></legend>
<input type="file" id="uploadfile" name="uploadfile" style="width: 370px; height: 22px" />
</fieldset>
</div>
</div>
</div>
<div id="AlertListDetails">
<table id="grdAlertListUpload" style="border-collapse: separate"></table>
</div>
}
Controller Code
[HttpPost]
public JsonResult SaveAlertList(HttpPostedFileBase uploadfile)
{
string message1 = string.Empty;
HttpPostedFileBase file = Request.Files["uploadfile"];
try
{
if (uploadfile != null && uploadfile.ContentLength != 0)
{
var fileName = Path.GetFileName(uploadfile.FileName);
if (fileName !=null)
{
var path = Path.Combine(Server.MapPath(UploadFolderPath), fileName);
uploadfile.SaveAs(path);
}
message1 = ConfirmationMessages.AlertListUploadComplete;
}
return Json(new { Result = "OK", Message1 = message1 });
}
catch(Exception ex)
{
LoggerService.Logger.Log(ex);
return Json(new { Result = "ERROR", Message1 = ex.Message });
}
}
Here is the jquery code
$("#btnUpload").on('click', function () {
loadingDialog.show("Saving data...");
performJsonCall(AlertListUpload.SaveAlertList, 'json', "", function(data) {
AlertListUpload.SaveSuccess(data);
});
});
Any help is appreciated.