I have a few strongly-typed partial views which displays output in a list format. Here is one of the Partials:
<%@ 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>
Here is how I access above partial in master:
<% using(Html.BeginForm("SaveStudentInvoice", "StudentInvoice")) %>
<% { %>
<% Html.RenderPartial("DisplayStudentInvoiceList"); %>
<input type="button" id="Submit" name="Submit" value="Submit" />
<% } %>
Now, I have a “Save” button in master which when I click should save Student ID, Past Due Amount and Past Due Days in a table. How can I access the partial view elements Ids and Names in Master view to do the insert?
Thanks in advance.
In ASP.NET MVC Views/MasterPages don’t do inserts. They display data. It’s controller actions that do inserts. The partial view example you have shown is only displaying the student data details as labels. If you want to send them back to the server (for insertion) you should use an HTML
<form>(<% using (Html.BeginForm("someAction", "someController")) { %>) and input fields (Html.EditorForhelper) instead of simple labels.