目前我有一個局部視圖,顯示與某個blogid關聯的數據庫中的評論。我無法得到這個爲我的生活工作。我甚至無法弄清楚如何將blogid傳遞給partial,所以我拉出正確的評論。這是我到目前爲止。在博客上顯示評論發佈信息
/博客/詳細註釋部分
<h2>Comments</h2>
<hr/>
@if (!User.Identity.IsAuthenticated)
{
<p>You Must Be Logged In To Comment.</p>
}
else
{
@: Posting comments as @User.Identity.Name<hr/>
@Html.Action("Create", "Comment", new {blogId = Model.Id});
@: <hr/>
}
@Html.Partial("_Comments")
_comments局部視圖
@model IEnumerable<GregG.Models.Comment>
@foreach (var item in Model) {
if (item.BlogId == 1) //I need to make this dynamic but can't figure out how to pass the id
{
<small>Posted by: @Html.DisplayFor(modelItem => item.UserName) on: @Html.DisplayFor(modelItem => item.PostedDate)</small>
@Html.DisplayFor(modelItem => item.Meat)<hr/>
}
}
我的第一個問題是:我如何通過我的博客ID給部分。 我的第二個問題是爲什麼我在我的部分行上收到此錯誤。
傳遞到詞典中的模型產品類型「System.Data.Entity.DynamicProxies.Blog_18032B13AD6163845F0AE57E827683E3638FD813CA4EE066F28D05E5406E633D」,但這需要字典類型的模型項「System.Collections.Generic.IEnumerable`1 [格雷格。 Models.Comment]」。
在此先感謝您的幫助。
我結束了使用@ Html.Action選項,它的工作完全謝謝! –