我得到传入字典的模型项是类型错误

时间:2012-05-04 06:44:46

标签: asp.net-mvc asp.net-mvc-3 razor partial-views

我正在使用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>

HomeController.cs

public ActionResult _Menu()
{
Blog.Models.BlogDataContext dc = new Models.BlogDataContext();
    return PartialView(dc.BlogCategories.ToList());
}

0 个答案:

没有答案