我遇到了一些麻煩。我有一個觀點如下在MVC應用程序中使用兩個模型,一個在視圖中,一個在部分中
@model IEnumerable<Tipstr.Models.Posts>
<div class ="mainC">
<div class = "leftContent">
@Html.Partial("_LeaderboardPartial")
</div>
<div class = "rightContent">
@foreach (var item in Model) {
<h1 class ="ptitle">
@Html.DisplayFor(modelItem => item.title)
</h1>
<p class ="date">
posted @Html.DisplayFor(modelItem => item.date)
</p>
<p class ="post">
@Html.DisplayFor(modelItem => item.body)
</p>
<hr />
}
</div>
</div>
<div class="Cpad">
<br class="clear" /><div class="Cbottom"></div><div class="Cbottomright">
</div>
</div>
而且我有一個部分,_LeaderboardPartial,如圖
@model IEnumerable<Tipstr.Models.Leaderboard>
<table id="pattern-style-a" summary="Meeting Results">
<thead>
<tr>
<th scope="col">Username</th>
<th scope="col">Tipster Score</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.userName)</td>
<td> @Html.DisplayFor(modelItem => item.score)</td>
</tr>
}
</tbody>
</table>
我似乎無法得到它的工作,我認爲這是與傳遞一個模型從佈局,然後是另一個從部分。我怎樣才能解決這個問題?我收到以下錯誤:
傳遞到字典中的模型項目類型爲'System.Collections.Generic.List 1[Tipstr.Models.Posts]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [Tipstr.Models.Leaderboard]'。
模型部分渲染時仍然是帖子視圖上使用的模型。你是否想渲染每篇文章的屬性? – devdigital 2013-04-30 15:54:39