经过多年在这里得到很多好建议后,我终于在墙上教自己MVC4 ASP.net了.
我用这个帖子这个帖子 从我的控制器通过Class类型的列表,我的看法,并回到控制器..
public ActionResult SelectProducts()
{
displayProductsList = db.Products.ToList();
displayProductsList.ForEach(delegate(Product p)
{
//get list of recievables for the product
GetReceivablesByProductId(p.ProductID).ForEach(delegate(Receivable r)
{
//Get count of items in inventory for each recievable
p.CurrentInventory += this.CountItemsByReceivableID(r.RecievableID);
});
});
return View(FilterProductInventoryList(displayProductsList));
}
Run Code Online (Sandbox Code Playgroud)
这是我的视图代码..
@model List<CarePac2.Models.Product>
@{
ViewBag.Title = "SelectProducts";
}
<h2>SelectProducts</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table>
@*row values*@
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>@Html.DisplayFor(m => m[i].Brand)</td>
<td>@Html.DisplayFor(m => m[i].ProductName)</td>
<td>@Html.DisplayFor(m => m[i].UnitType)</td>
<td>@Html.DisplayFor(m …Run Code Online (Sandbox Code Playgroud)