MVC3 jak opublikować listę w klasie w kontrolerze?
Mam klasę:
public class CarList
{
public int quantity{get;set;}
public List<Car> Cars {get;set;}
}
public class Car {
public string Name {get;set;}
}
Następnie tworzę listę samochodów z trzema samochodami na liście. Następnie wyświetlam informacje na ekranie za pomocą modelu pętli. Kiedy przesyłam formularz, pole ilości ma prawidłową wartość, ale samochody są puste.
[HttpPost]
public ActionResult Save(CarList list)
{
//why is list.Cars NULL when i am posting three items in the list
}
Widok: Model = Samochód, dodano wiersz
Dodano nowy szablon edytora dla samochodu z<tr><td>Name</td><td>Html.TextBoxFor(x=>Model.Name)</td></tr>
W głównym widoku: Model = CarList, dodano forloop
@{foreach (Car item in Model.Cars)
{
@Html.EditorFor(x=>item);
}