Да, вы можете сделать это с помощью небольшого браузера jquery и HTML 5.
$('#YourFormId').submit(function() {
var formData = new FormData($('form')[0]);
$.ajax({
url: this.action,
cache: false,
type: this.method,
data: formData,
success: function (result) {
},
beforeSend: function (e) {
},
contentType: false,
processData: false
});
// it is important to return false in order to
// cancel the default submission of the form
// and perform the AJAX call
return false;
});
Я получил этот код у кого-нибудь, возможно, на этом сайте. Я постоянно вижу, что люди говорят, что вы не можете этого сделать, но он работает в IE 10+ и Chrome.
ViewModel выглядит следующим образом:
public class MyModel
{
public string mytest { get; set; }
public string mytest2 { get; set; }
public string status { get; set; }
public HttpPostedFileBase fileupload {get;set;}
}
Действие выглядит следующим образом:
[HttpPost]
public ActionResult YourActionName(YourModel model)
{
return whatever();
}