So I have an MVC action with the header:
public PartialViewResult PersistPlaceholderItems(ModelObject model, int start, int count)
So it’s expecting three things. First thing is an object, the other two are just simple ints.
This is what I have so far for my AJAX call:
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(model),
success: function (result) {
$("#panel").html(result);
},
error: function (event) {
alert("Error!");
}
});
Stringifying model just gives me the first thing I need in PersistPlaceholderItems. I need start and count as well. I just don’t know how to format the JSON string to include them along with the model object.
I tried:
data: [{model: JSON.stringify(model)}, {start:start}, {count:count}]
But it gave me an error. How do I format it so I can send all three items to the server?
Edit: Ideally, I would like to just send three things instead of having to wrap it into another viewmodel. I don’t want a viewmodel inside of a viewmodel just so I can send two additional ints.
You need: