MVC2應用,我們可以做一個網頁,在同一個地方輸入和顯示列表
下面我有兩條表代碼首先是顯示輸入字段和第二個是顯示列表,問題是,在輸入字段中顯示其集合與此綁定。
代碼查看
<h2>AddmissionCellWithModel</h2>
<div>
<% using (Html.BeginForm("InsertN", "AddmissionCell", FormMethod.Post))
{ %>
<table>
<tr>
<td>
Student's Name:
</td>
<td>
<%= Html.TextBox("StudentName", Model)%>
</td>
<td>
Addmission Year:
</td>
<td>
<%= Html.TextBox("AddmissionYear", Model)%>
</td>
</tr>
<tr>
<td>
Father's Name:
</td>
<td>
<%= Html.TextBox("FatherName", Model)%>
</td>
<td>
Mother's Name:
</td>
<td>
<%= Html.TextBox("MotherName", Model)%>
</td>
</tr>
<tr>
<td>
Contact:
</td>
<td>
<%= Html.TextBox("Contact", Model)%>
</td>
<td>
Address:
</td>
<td>
<%= Html.TextBox("Address", Model)%>
</td>
</tr>
<tr>
<td>
SchoolName:
</td>
<td>
<%= Html.TextBox("SchoolName", Model)%>
</td>
<td>
EnrollmentId:
</td>
<td>
<%= Html.TextBox("EnrollmentID", Model)%>
</td>
</tr>
<tr>
<td colspan="4" align="right">
<input type="submit" value="Save" />
</td>
</tr>
<tr>
<td colspan="4">
</td>
</tr>
<tr>
<td colspan="4">
</td>
</tr>
</table>
<%} %>
</div>
<table>
<tr>
<th>
EnrollmentID
</th>
<th>
StudentName
</th>
<th>
SchoolName
</th>
<th>
StudentID
</th>
<th>
FatherName
</th>
<th>
MotherName
</th>
<th>
Address
</th>
<th>
Contact
</th>
<th>
ClassId
</th>
<th>
AddmissionYear
</th>
<th>
EnrollDateTime
</th>
<th>
IsActive
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: item.EnrollmentID %>
</td>
<td>
<%: item.StudentName %>
</td>
<td>
<%: item.SchoolName %>
</td>
<td>
<%: item.StudentID %>
</td>
<td>
<%: item.FatherName %>
</td>
<td>
<%: item.MotherName %>
</td>
<td>
<%: item.Address %>
</td>
<td>
<%: item.Contact %>
</td>
<td>
<%: item.ClassId %>
</td>
<td>
<%: item.AddmissionYear %>
</td>
<td>
<%: String.Format("{0:g}", item.EnrollDateTime) %>
</td>
<td>
<%: item.IsActive %>
</td>
</tr>
<% } %>
</table>
和控制器代碼...
公衆的ActionResult AddmissionCellWithModel(){
SchoolManagementV1Entities db = new SchoolManagementV1Entities();
List<EnrollmentModel> result = (from q in db.VW_EnrollmentModel
select new EnrollmentModel()
{
EnrollmentID = q.EnrollmentId,
StudentName = q.StudentName,
StudentID = q.StudentID,
FatherName = q.FatherName,
MotherName = q.MotherName,
Address = q.Address,
Contact = q.Contact ?? 0,
AddmissionYear = q.EnrollYear,
EnrollDateTime = q.AdmissionDateTime,
IsActive = q.EnrollIsActive
}).ToList();
return View(result);
}
這個回報的觀點是結果對象返回到視圖
所以一些在告訴我怎樣才能防止顯示System.Collection.Generic ....