0
這裏是我的博文模型類:System.Collections.Generic.IEnumerable <MyBlogSite.Models.BlogPost>」不包含定義 '分類'
public class BlogPost
{
public int Id { get; set; }
public string Title { get; set; }
[AllowHtml]
public string ShortDescription { get; set; }
[AllowHtml]
public string PostBody { get; set; }
public string Meta { get; set; }
public string UrlSlug { get; set; }
public DateTime PostedOn { get; set; }
public DateTime? Modified { get; set; }
public virtual ICollection<BlogPostCategory> Categories { get; set; }
public virtual ICollection<BlogPostTag> Tags { get; set; }
}
這裏是我BlogPostCategory模型類:
public class BlogPostCategory
{
public int Id { get; set; }
public string Name { get; set; }
public string UrlSlug { get; set; }
public string Description { get; set; }
// Decared virtual because the data must be returned from another table.
public virtual ICollection<BlogPost> BlogPosts { get; set; }
}
每個類屬於一個單獨的控制器/視圖。
最後,這裏是索引視圖爲博客頂部的端口:
@model IEnumerable<MyBlogSite.Models.BlogPost>
@{
ViewBag.Title = "Index";
}
@Html.RenderPartial("~/Views/Category/_Categories.cshtml", Model.Categories);
<p>
@Html.ActionLink("New Blog Post", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
....
在Model.Categories正在被傳遞的觀點是在那裏我得到這個職位的標題除外。在我看來,我已經在BlogPost模型中定義了類別。我究竟做錯了什麼?