I have an USER and a CAR class.
I know how build an USER CREATE form, naming simple element same as the field on db (like name, phonenumber) so on SUBMIT the Action method get every element and I can save it to db.
Now on the CREATE form I also want user add CARS, and on SUBMIT send List.
How I do that?
For example I can return a collection like this Or return one car element, creating an input for each car property.
<form method="post" action="/Home/UpdateInts">
<input type="text" name="cars" value="1" />
<input type="text" name="cars" value="4" />
<input type="text" name="cars" value="2" />
<input type="text" name="cars" value="8" />
<input type="submit" />
</form>
public ActionResult UpdateInts(ICollection<int> cars) {
SaveMethod(cars);
}
But how I do to receive
public ActionResult UpdateInts(ICollection<Car> myCars) {
SaveMethod(myCars);
}
Cuurently Im using jQuery EasyUI grid To add cars, make and model during the create user page.
name="[0].Make",name="[0].Model",name="[1].Make",name="[1].Model"etc. Some options to consider for dynamically creating new items in a view here and here