List<MenuProduct> MenuProducts;
其中
MenuProduct
public class MenuProduct
{
public int MenuProductID { get; set; }
public int LoginID { get; set; }
public int ContractTypeID { get; set; }
public int? ContractID { get; set; }
public string Title { get; set; }
public decimal? Factor { get; set; }
public int OrderNum { get; set; }
public System.DateTime DateCreated { get; set; }
public int UserCreated { get; set; }
public decimal DiscountedRate { get; set; }
public decimal? JointFactor { get; set; }
}
和(部分)模型:
public List<MenuProduct> MenuProducts { get; set; }
public SelectList ContractTypes { get; set; }
public SelectList Contracts { get; set; }
我把它们绑在这样的视图中:
@for (int i = 0; i < Model.MenuProducts.Count(); i++)
{
<tr>
<td>@Html.TextBoxFor(x => x.MenuProducts[i].Title, new { @class = "form-control" })</td>
<td>@Html.TextBoxFor(x => x.MenuProducts[i].Factor, new { @class = "form-control" })</td>
<td>@Html.TextBoxFor(x => x.MenuProducts[i].JointFactor, new { @class = "form-control" })</td>
<td>@Html.DropDownListFor(x => x.MenuProducts[i].ContractTypeID, Model.ContractTypes, new { @class = "form-control" })</td>
<td>@Html.DropDownListFor(x => x.MenuProducts[i].ContractID, Model.Contracts, new { @class = "form-control" })</td>
</tr>
}
如果我将每个项目移动到这样的局部视图:
@for (int i = 0; i < Model.MenuProducts.Count(); i++)
{
@Html.RenderPartial("_MenuProductItemPartialView", new MenuProductItemModel() { Item = Model.MenuProducts[i], ContractTypes = Model.ContractTypes, Contracts = Model.Contracts})
}
使用此型号:
public MenuProduct Item { get; set; }
public SelectList ContractTypes { get; set; }
public SelectList Contracts { get; set; }
选择列表中的值是正确的,但是我不能在外部页面上有一个按钮来同时更新所有行-至少,我不知道怎么做。
所以我的问题是:如何让选择列表以第一种方式工作(在那里我可以发回
List<MenuProduct>
)或者,我如何通过第二种方式从每个部分收集所有更新的数据?因为可能有来自任何行或多行的数据发生了更改。