I am uploading a file in my ASP.NET MVC application. In the .ascx file, I have the following:
<form action="/Admin/Mail/ABC" enctype="multipart/form-data" method="post">
<div>
<input type="file" name="file" id="file" />
<input type="submit" value="Upload" id="UploadList" onclick="Origin.UploadOptOutList();"/>
</div>
in the .js file:
Origin.UploadList = function () {
Origin.ajax({
url: '/Admin/Mail/Upload',
type: 'POST',
dataType: 'json',
success: function (data) {
alert('success!');
}
});
}
and the controller:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
List<string> validIDs, invalidIDs;
if (file.ContentLength > 0)
{
// do something
}
}
When invoking the Action from .js, the 'file' is always NULL. Any idea what I am missing?