Sré*_*áîr 1 asp.net-mvc razor asp.net-mvc-4 uicollectionview
如何在ASP.NET MVC Razor项目中显示集合?
我的模型和视图如下.对于一个人,我要在屏幕上显示许多测试.提前致谢
namespace UI.Models
{
public class SuperStudent
{
public string FullName { get; set; }
public ICollection<TestDetail> CandidateTestDetails { get; set; }
}
public class TestDetail
{
public DateTime TestDate { get; set; }
public string RegNum { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
}
视图
@model IEnumerable<UI.Models.SuperStudent>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FullName)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
Print all test details
</td>
</tr>
}
</table>
Run Code Online (Sandbox Code Playgroud)
对于一个人,您的观点必须如下:
@model UI.Models.SuperStudent
<h2>@Model.FullName</h2>
<table class="table">
<tr>
<th>
TestDate
</th>
<th>
RegNum
</th>
</tr>
@foreach (var item in Model.CandidateTestDetails ) {
<tr>
<td>
@item.TestDate
</td>
<td>
@item.RegNum
</td>
</tr>
}
</table>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4662 次 |
| 最近记录: |