如何在ASP.NET MVC Razor项目的视图中显示集合? [英] How to display a collection in View of ASP.NET MVC Razor project?

查看:262
本文介绍了如何在ASP.NET MVC Razor项目的视图中显示集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.NET MVC Razor项目的视图中显示集合?

How to display a collection in View of ASP.NET MVC Razor project?

我的模型和视图在下面.对于一个人,我必须在屏幕上显示许多测试.在此先感谢

My Model and View is below. For one person i've to display Many tests on the screen. Thanks in Advance

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; }     
}

}

查看

@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>

推荐答案

对于一个人,您的观点必须像:

For one person your view must be like :

@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>

这篇关于如何在ASP.NET MVC Razor项目的视图中显示集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆