在另一个模型中使用的访问模型列表

时间:2015-03-11 13:47:51

标签: asp.net-mvc-4 c#-5.0

我有以下代码。我想在我使用DTOQuestions

的视图中使用List的对象
//My Model Question
public class Question
{
    public int Question_Id { get; set; } 
    public string Question_Title { get; set; }
    public List<Reply> Reply_List { get; set; }
}

//My 2nd Model Answer
public class Reply
{
    public int Reply_Msg { get; set; }
    public int Attachment_Id { get; set; }
}

//View
    @foreach(var item in Model)
    {
        foreach(var replylbl in item.Forum_Reply_List)
        {
            <th>@Html.DisplayNameFor(replymodel => replylbl.Reply_Msg)</th>
            <th>@Html.DisplayNameFor(replymodel => replylbl.Attachment_Id)</th>
        }
    }


    @foreach (var item in Model) {
    <tr>
       <td>
        @foreach (var reply in item.Forum_Reply_List){@Html.DisplayFor(modelReply => reply.Reply_Msg)}
    </td>
    <td>
        @foreach (var reply in item.Forum_Reply_List){@Html.DisplayFor(modelReply => reply.Attachment_Id)}
    </td>

我有这两个模型和以下视图。现在我想在我的视图中访问具有模型类型问题的答案(回复)模型对象 但是在视图中我无法显示这些列的标题..

0 个答案:

没有答案