我正在研究 MVC-3。我认为我面临以下异常:
cannot perform runtime binding on a null reference
模型类
public class HomeModel
{
public IEnumerable<Html> Template { get; set; }
}
查看代码
@model Project.Models.HomeModel
@{
ViewBag.Title = "Home Page";
int i = 0;
}
<div class="container">
@foreach (var e in Model.Template) //getting exception on this foreach loop
{
//loop content
}
</div>
控制器
public ActionResult Index()
{
HomeModel model = new HomeModel();
model.Template = db.Templates();
return View(model);
}
我的视图是 HomeModel 模型类的强类型。谁能帮我解决这个问题?