我試圖在索引文件中顯示價格。 但是,它顯示空白字段。我的編碼有什麼問題? 你能幫我嗎?這應該是容易的問題。但我找不到它。 如果您提供一些反饋,我真的很感謝你!MVC3 ViewBag不起作用
public ActionResult Index(decimal priceValue)
{
var cart = ShoppingCart.GetCart(this.HttpContext);
// Set up our ViewModel
decimal price = priceValue;
ViewBag.eachPrice = price;
var viewModel = new ShoppingCartViewModel
{
CartItems = cart.GetCartItems(),
CartTotal = cart.GetTotal(price)
};
// Return the view
return View(viewModel);
}
Index.cshtml
@foreach (var item in Model.CartItems)
{
<tr id="[email protected]">
<td>
@Html.ActionLink(item.Product.model, "Details", "Store", new { id = item.productId }, null)
</td>
<td>
//here!! is it wrong?
@ViewBag.eachPrice
</td>
<td id="[email protected]">
@item.count
</td>
<td>
@item.dateCreated.Date.ToString("dd MMM yyyy")
</td>
<td>
@*how about using some model instead of number?*@
@item.dateCreated.Date.AddDays(2).ToString("dd MMM yyyy")
</td>
<td>
</td>
<td>
<a href="#" class="RemoveLink" data-id="@item.recordId">
Remove from cart</a>
</td>
</tr>
}
它看起來的代碼,它應該工作,你有沒有嘗試調試視圖,看看值是否存在? – Yasser 2012-04-02 07:41:43