2014-03-19 36 views
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" /> 

的問題是,在第二項中,當等級分視圖(上面的局部視圖)被再次調用,被旁邊的第一產品的星下面顯示的星星,圖片。

enter image description here

我想我不得不使用別的東西,而不是Html.Action

編輯:showAverageRating代碼

public ActionResult showAverageRating(int ProductID) 
{ 
    decimal averageRating = new RatingsService.RatingsClient().getAverageRating(ProductID); 
    ViewData["averageRating"] = averageRating; 
    return PartialView(); 
} 
+0

可以張貼showAverageRating行動碼 –

+0

公共的ActionResult showAverageRating(INT的ProductID) { 小數averageRating =新RatingsService.RatingsClient()getAverageRating(產品ID)。 ViewData [「averageRating」] = averageRating; return PartialView(); } – drinu16

+0

檢查主文章的編輯,比以上評論更好 – drinu16

回答

1

的問題是相同的地方,所以我包含產品ID與他們的名字,像下面的明星的名字。

showAverageRating局部視圖

@{decimal averageRating = ViewBag.averageRating;} 
@{int productID = ViewBag.productID;} 

<div id="averageRating" > 
    <input class="star" name="[email protected]" type="radio" /> 
    <input class="star " name="[email protected]" type="radio" /> 
    <input checked="checked" class="star " name="[email protected]" type="radio" /> 
    <input class="star " name="[email protected]" type="radio" /> 
    <input class="star " name="[email protected]" type="radio" /> 
</div> 
相關問題