Your action should like this:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file) {
if (file.ContentLength > 0) {
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
Taken from :http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx/
Then using jQuery Dialog for file upload:
$dialog.dialog("option", "buttons", {
"Save": function () {
var dlg = $(this);
var formData = new FormData($("#" + formName)[0]);
$.ajax({
url: /Controller/upload,
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (response, textStatus, xhr) {
...
}
},
error: function (xhr, status, error) {
....
}
});
},
"Cancel": function () {
$(this).dialog("close");
$(this).empty();
}
});