Post Files and JSON using jQuery AJAX
var fileArray = $("#imageFile")[0].files;
var formData = new FormData();
// Gets the json model from ko, then adds to the formdata collection
var model = ko.toJS(model.user);
formData.append("model", JSON.stringify(model));
for (var i = 0, f; f = fileArray[i]; i++) {
formData.append("opmlFile", f);
}
$.ajax({
url: "/Profile/Save/",
type: "POST",
data: formData,
cache: false,
contentType: false,
processData: false
})
.error(function (xhr, status, error) {
$.notify(error, true);
})
.success(function (data, status, xhr) {
$.notify("User Profile Saved");
});