我正在使用 MVC3 Razor 开发一个博客,我正在尝试在我的项目中使用 partialview,但出现以下错误:
System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Blog.Models.BlogPost]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Blog.Models.BlogCategory]'.
_Layout.cshtml
@Html.Partial("_Menu")
_Menu.cshtml
@model IEnumerable<Blog.Models.BlogCategory>
<ul>
@foreach (var item in Model)
{
<li><a href="#">@item.CategoryName</a></li>
}
</ul>
家庭控制器.cs
public ActionResult _Menu()
{
Blog.Models.BlogDataContext dc = new Models.BlogDataContext();
return PartialView(dc.BlogCategories.ToList());
}