我在改写这个问题:模型计数= null
我有2个模型。入口和主题。
public class Entry
{
public int EntryId { get; set; }
public int UserId { get; set; }
public int TopicId { get; set; }
public String EntryQuestion { get; set; }
public String EntryAnswer { get; set; }
public int EntryReview { get; set; }
public String QuestionValidationURL { get; set; }
public virtual ICollection<Topic> TopicList { get; set; }
}
public class Topic
{
public int TopicId { get; set; }
public String TopicName { get; set; }
}
我跟着一个关于ASP.Net/MVC的例子来设置我的模型。 我想要做的是为每个项目我有一个TopicId,但是我想通过访问我的TopicList将其转换为TopicName。
我的问题是,我如何加载TopicList?
在下面的例子中,我看到了一些关于LazyLoading和EagerLoading的内容,但它似乎没有工作。
我试着做从我的输入控制器如下:
db.Entries.Include(x => x.TopicList).Load();
但是,这仍然给我的0题目列表(比空好)
我怎样才能做到这一点?
在我看来,我绑定到的条目是这样的:
@model IEnumerable<projectInterview.Models.Entry>
我想访问这里的题目列表:
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TopicId)
</td>
...
</tr>
我想用TopicId在这循环并显示属于集合中对象一部分的TopicName。
请显示您如何绑定模型并在视图中使用它。 – Dima
已更新问题 – webdad3
请显示'getTopicsCount()'方法 – bazz