I have following data to send ajax call to the controller action:
var data = {
"PersonalInfo": [
{
"FirstName": "Leonel",
"LastName": "Messi"
},
{
"FirstName": "Cristiano",
"LastName": "Ronaldo"
}
]
};
Ajax call method:
$.ajax({
url: "/Home/Create",
type: "POST",
dataType: "json",
data: (JSON.parse(data)).PersonalInfo,
success: function (response) { }
});
Controller Action:
public ActionResult Create(FormCollection formCollection)
{
base.Create(formCollection);
}
In server side, I need array/list of FormCollection
, e.g.:
formCollection[0] = {
"FirstName": "Leonel",
"LastName": "Messi"
}
formCollection[1] = {
"FirstName": "Cristiano",
"LastName": "Ronaldo"
}
Or something like following code so that I can call base.Create(formCollection)
method multiple times for multiple personal info.
public ActionResult Create(List<FormCollection> formCollection)
{
}
But it is not possible, are there any alternative for this context?
FormCollection
? Use a model withFirstName
andLastName
properties and bind to a collection of your model -public ActionResult Create(List<Person> model)