I have a regular form on view with a set of inputs. I use jQuery to serialize and post it.
$("#formId").submit(function (e) {
e.preventDefault();
var fields = {};
var formSerialized = $("#formId").serializeArray();
$.each(formSerialized, function (i, field) {
fields[field.name] = field.value; });
e.data = fields;
$.post("myUrl", {
FirstName: e.data.FirstName,
LastName: e.data.LastName
}, function (success) {
if (success) {
alert('Ok')
} else {
alert('fail');
}
});
}
});
On backend I have ASP.NET WebAPI2 server with action that gets this request and automatically binds all properties to model.
Now I need to add multiple file inputs to the same form.
Is there a way to: - send files and regular properties that I send in code sample in the same time in the same request? - is it possible to extend model on WebAPI side with HttpPostedFileBase properties and to keep automatic binding of data?
What is the best way to send regular text properties (values from form) + multiple files in the same request to process them in one single method on WebAPI2 side?
Thanks!