In MVC4, how do you pass a javascript object to a C# controller in AJAX? Finally I tried this but it did not work.
Javascript Client side:
The value you pass for the data
property should be an object, not a string:
data: myData,
the property names need to match:
var myData = { Prop1: '', Prop2: ''};
you need to use the [FromBody]
attribute on your parameter value:
public ActionResult SubmitMyData([FromBody] MyParamModel myParam)
and the properties on your model type need to be public
:
public class MyParamModel
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}