I'm trying to post a simple viewmodel in MVC core using a jquery AJAX post, however the IFormFile property seems to be null on the model.
I have the following view model:
[Required]
public IFormFile File { get; set; }
[Required]
[Display(Name = "Owner")]
public int DocumentOwner { get; set; }
[Required]
[Display(Name = "Document Type")]
public int DocumentTypeId { get; set; }
I then use a jQuery ajax post inside a script at the bottom of my view:
$("form").submit(function (e) {
e.preventDefault();
var model = $('form').serialize();
$.ajax({
type: "POST",
url: "/Client/AddDocument",
contentType: false,
processData: false,
data: model,
success: function (message) {
alert(message);
},
error: function () {
alert("There was error uploading files!");
}
});
});
The viewmodel is successfully passing the other values to the controller, however the file is coming through as null.
Anyone able to help?