I have a class:
public class CarList
{
public int quantity{get;set;}
public List Cars {get;set;}
}
public class Car {
public string Name
Use an EditorTemplate and you will be good.
Create a Folder Called "EditorTemplates" and create a view (the editor template) with the name Car.cshtml
Now Add the below code to this new view.
@model Car
@Html.TextBoxFor(x => x.Name)
Now in your Main View, Use the Html.EditorFor HTML helper method to call this editor template
@model SO_MVC.Models.CarList
CarList
@using (Html.BeginForm())
{
Quanitty
@Html.TextBoxFor(x => x.quantity)
@Html.EditorFor(x=>x.Cars)
}
Now have an HTTPPOst action method to accept the form posting
[HttpPost]
public ActionResult CarList(CarList model)
{
//Check model.Cars property now.
}
You will see the results now