Ich versuche, den Preis in der Indexdatei anzuzeigen. Es zeigte jedoch leeres Feld. Was ist falsch mit meiner Codierung? Können Sie mir helfen? Es sollte ein leichtes Problem sein. Aber ich kann es nicht finden. Wenn Sie ein Feedback geben, bin ich wirklich danke!MVC3 ViewBag funktioniert nicht
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>
}
der Code, wie es aussieht, sollte es funktionieren, haben Sie versucht, die Ansicht zu debuggen und sehen, ob der Wert dort ist? – Yasser