0
我是MVC的新手,希望得到一些帮助。在同一视图中多次执行相同的局部视图
我有一个视图(下面)显示产品,彼此相邻。直到这里一切都很好。
@foreach (var item in Model)
{
<a href="@Url.Action("showProductDetails", "Shared", new { ProductID = item.ProductID }, null)">
<div class='OutsideDiv' >
<table class='DivBorder'>
<tr >
<td class='title'>
@item.ProductName
</td>
</tr>
<tr >
<td class='imageBox'>
<img alt='' src="@item.ImageURL" />
</td>
</tr>
<tr>
<td class='title'>
@Html.Action("showAverageRating", "Rating" , new { ProductID = item.ProductID } ) *************
</td>
</tr>
<tr>
<td class='desc'>
@item.Description
</td>
</tr>
<tr>
<td class='price'>
€ @item.Price
</td>
</tr>
</table>
</div>
<script type='text/javascript'> $('.DivBorder').mouseover(function() { $(this).css('border-color', '#0953cb'); $(this).css('background-color', '#eaeaea'); }); $('.DivBorder').mouseout(function() { $(this).css('border-color', '#bdbdbd'); $(this).css('background-color', '#f6f6f6'); });</script>
</a>
}
在线标有“****”高于我打电话这对于现在只显示5等级分与选择的第一3点开始另一视图(showAverageRating)。
<input class="star " name="adv1" type="radio" />
<input class="star " name="adv1" type="radio" />
<input checked="checked" class="star " name="adv1" type="radio" />
<input class="star " name="adv1" type="radio" />
<input class="star " name="adv1" type="radio" />
的问题是,在第二项中,当等级分视图(上面的局部视图)被再次调用,被旁边的第一产品的星下面显示的星星,图片。
我想我不得不使用别的东西,而不是Html.Action
?
编辑:showAverageRating代码
public ActionResult showAverageRating(int ProductID)
{
decimal averageRating = new RatingsService.RatingsClient().getAverageRating(ProductID);
ViewData["averageRating"] = averageRating;
return PartialView();
}
可以张贴showAverageRating行动码 –
公共的ActionResult showAverageRating(INT的ProductID) { 小数averageRating =新RatingsService.RatingsClient()getAverageRating(产品ID)。 ViewData [“averageRating”] = averageRating; return PartialView(); } – drinu16
检查主文章的编辑,比以上评论更好 – drinu16