C# IEnumerable ViewModel不允许我访问模型属性

C# IEnumerable ViewModel不允许我访问模型属性,c#,asp.net-mvc,viewmodel,ienumerable,C#,Asp.net Mvc,Viewmodel,Ienumerable,当模型是IEnumerable类型时,我在访问视图中模型的属性时遇到问题 我的控制器代码: // // GET: /Home/ public ActionResult Index() { List<CourseworkQuestion> courseworkQuestions = repository.GetCourseworkQuestions(repository.GetUsername()).ToList(); List<HomeViewModel>

当模型是IEnumerable类型时,我在访问视图中模型的属性时遇到问题

我的控制器代码:

//
// GET: /Home/
public ActionResult Index()
{
    List<CourseworkQuestion> courseworkQuestions = repository.GetCourseworkQuestions(repository.GetUsername()).ToList();
    List<HomeViewModel> model = new List<HomeViewModel>();

    foreach (CourseworkQuestion courseworkQuestion in courseworkQuestions)
    {
        HomeViewModel hvm = new HomeViewModel(courseworkQuestion);
        model.Add(hvm);
    }

    return View(model);
}
在我看来:


我肯定我以前做过,但我不确定我是否遗漏了一些明显的内容。

您需要在页面中包含一个using来获取System.Collections.Generic命名空间:

<%@ Import namespace="System.Collections.Generic" %>
<%@ Import namespace="System.Linq" %> //To get all the LINQ extension methods
或完全限定对IEnumerable的引用:
System.Web.Mvc.ViewPage>

谢谢您的帮助。我不熟悉ASP.NET和MVC。你能告诉我如何进行include吗?我似乎得到了其他方法和扩展,比如Aggregate、All等,但没有我的属性。