【发布时间】:2012-07-16 21:45:15
【问题描述】:
我有几个以列表格式显示输出的强类型部分视图。这是其中一个部分:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Student.Models.vwStudent>>" %>
<table>
<tr>
<th>
Student ID
</th>
<th>
Past Due Amount
</th>
<th>
Past Due Days
</th>
</tr>
<% if (Model != null)
foreach (var item in Model) { %>
<tr>
<td>
<%=Html.TextBox("StudentID",item.StudentID) %>
</td>
<td>
<%=Html.TextBox("PastDueAmount",item.PastDueAmount) %>
</td>
<td>
<%=Html.TextBox("PastDueDays",item.PastDueDays) %>
</td>
</tr>
<% } %>
</table>
这是我在 master 中访问以上部分的方式:
<% using(Html.BeginForm("SaveStudentInvoice", "StudentInvoice")) %>
<% { %>
<% Html.RenderPartial("DisplayStudentInvoiceList"); %>
<input type="button" id="Submit" name="Submit" value="Submit" />
<% } %>
现在,我在 master 中有一个“保存”按钮,当我单击该按钮时,应将学生 ID、逾期金额和逾期天数保存在表格中。如何访问主视图中的部分视图元素 ID 和名称来进行插入?
提前致谢。
【问题讨论】:
-
我认为您应该在部分中包含保存按钮,但您可以使用 JavaScript。尚未检查,但它应该类似于
document.forms[0].submit();,除非您有更多表格。比改变索引。
标签: c# asp.net-mvc linq-to-sql partial-views