【发布时间】:2016-03-22 06:08:22
【问题描述】:
我有 aspx 页面。我在表格中显示数据。如何从 Controller 中的此表中获取新值。或者如何在 mvc 的 aspx 页面中生成网格/表格的另一种方法?
<table id="Products" class="Products">
<tr>
<th>ProductId</th>
<th>Productname</th>
<th>Quantity</th>
<th>UnitPrice</th>
</tr>
<% foreach (var item in Model.NorthOrderDetails)
{
%>
<tr>
<td><%: item.ProductID %></td>
<td><%: item.ProductName %></td>
<td><%: Html.TextBox("Quantity",item.Quantity) %></td>
<td><%: Html.TextBox("UnitPrice",item.UnitPrice) %></td>
<td> <%: Html.ActionLink("Update", "View2") %></td>
</tr>
<% } %>
</table>
【问题讨论】:
-
您需要一个
for循环(不是foreach循环)-for(int i = 0; i < Model.NorthOrderDetails.Count; i++) { @Html.TextBoxFor(m => m.NorthOrderDetails[i].Quantity) .....}以便控件使用索引器正确命名,并且可以在回发时绑定到您的集合 -
@StephenMuecke.好的,谢谢。以及如何将新值发送到控制器中的方法 View2,如果我有这个方法并且它显示了这个表?
-
您的意思是在视图中动态添加新项目吗?
-
没有。更新文本框中的值
-
如果您使用
for循环,正如我所展示的,并且您回发模型,它将被正确绑定。您没有显示任何控制器方法或模型,因此如果它不工作,很难看出您可能做错了什么
标签: c# asp.net-mvc asp.net-mvc-4