我有一個Index View
與一個表填充List屬性的數據,但是當我發佈窗體的表,該屬性爲空。MVC發送一個對象列表
這裏是型號:
public class BillViewModel
{
public List<Product> ListProducts { get; set; }
}
這裏是產品的看法:
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal Price { get; set; }
}
這裏是查看:
@using (Html.BeginForm())
{
<input type="submit" value="Aceptar"/>
<table id="tabla">
@foreach (var item in Model.ListProducts)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
</tr>
}
</table>
}
我可以添加或刪除產品,但如何我可以在控制器中獲得產品列表嗎?:
[HttpPost]
public ActionResult Index(BillViewModel billViewModel)
{
return View();
}
請查看這個答案:http://stackoverflow.com/questions/ 17450772/asp-net-mvc4-dynamic-form-generation/17451048#17451048這是同樣的問題,我相信它會解決你的問題。 –
是的,你可以在你的控制中獲得所有細節。 Mvc流程是該控制器與模態和視圖進行通信。 –