I have got a form that I can successfully send to my controller action:
this.submitForm = function (e) {
var formData = $("#FinalizeForm").serialize();
$.ajax({
type: "POST",
url: '/MyController/MyMethod',
data: formData
});
My controller:
[HttpPost]
public void MyMethod(SomeModel model)
And works fine. However, I want to send additional data along with the form's, something like:
var test = {
name: 'Mike',
age: '40',
nationality: 'Portuguese'
}
$.ajax({
type: "POST",
url: '/MyController/MyMethod',
data: {
model: formData,
test: test
}
});
And the controller:
[HttpPost]
public void MyMethod(SomeModel model, AnotherModel test)
But this way, the model
variable comes null and the test
one comes populated. Why is this? Why did the model come populated before and now doesn't?
I tested sending it alone but in a different way:
$.ajax({
type: "POST",
url: '/MyController/MyMethod',
data: {
model: formData
}
});
But model
still comes as null.