I have the following problem:
On the click button, I will send some data to the server. The action of my controller is as follows:
public ActionResult Accept(List<MyViewModel> entries) {
Where MyViewModel looks like this:
public class MyViewModel { public string ParamA { get; set; } public string ParamB { get; set; } }
And AJAX-Call is:
var myEntries = { entries: [{ ParamA: "A", ParamB: "B" }, { ParamA: "C", ParamB: "D" }] }; $.ajax({ type: 'POST', url: url, cache: false, data: myEntries, dataType: 'text' });
What I already tried to do:
- Changed dataType type to 'json'
- used: traditional: true
- tried var myEntries = JSON.stringify (...);
- try var myEntries = {entries: [JSON.stringify ({...}), JSON.stringify ({...})]};
- same as above, but with jQuery.param (..., true);
- Using IEnumerable or MyViewModel [] instead of a list.
- ANY combination of the above
What am I doing wrong here?
Thank you very much in advance for your help!
EDIT
My (Razor) View is not interesting at the moment, because it has nothing to do with it. I DO NOT use any HTML.TextBoxFor (or similar) methods to populate myEntries-Variable. It actually populates dynamically (because there are many conditions). For the sake of the question (and my own testing) I hard-coded the variable. :)
jquery ajax asp.net-mvc-3 model-binding
Shion
source share