I have a form that uses jquery $.post to send the following JSON to the server:
{
id: 1,
label: "myLabel",
results: [
{ name: "myName1", value: "myValue1" },
{ name: "myName2", value: "myValue2" }
]
}
The JSON is posted to a controller similar to this:
public ActionResult Submit(int id, string label, List<object> results){...}
I also have the following class:
public class FormValue {
public string name {get;set;}
public string value {get;set;}
}
I'd like to be able to cast the contents of the JSON 'results' array to the 'FormValue' class in such a way that I could write the controller as:
public ActionResult Submit(int id, string label, List<FormValue> results){...}
What am I missing?
results: [ { ... }, { ... } ]public class Model{public string Id {get;set;} public string Label {get;set;} public List<FormValues> Results {get;set;}}. That type then becomes the single parameter in your action method.