0

我正在尝试在索引文件中显示价格。但是,它显示空白字段。我的编码有什么问题?你可以帮帮我吗?这应该是简单的问题。但我找不到它。如果您提供一些反馈,我真的很感谢您!

 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);
    }

索引.cshtml

@foreach (var item in Model.CartItems)
{
    <tr id="row-@item.recordId">
        <td>
            @Html.ActionLink(item.Product.model, "Details", "Store", new { id = item.productId }, null)
        </td>
        <td>
            //here!! is it wrong?
            @ViewBag.eachPrice
        </td>
        <td id="item-count-@item.recordId">
            @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>
}
4

2 回答 2

0

在VB中,我这样做:

 @code
   Dim price = viewbag.price
 @End code

然后,我在我想要的地方显示值

 @Html.Raw(price)

在cs中,我认为你必须用“var”代替“Dim”,并用“;”结束指令

于 2012-04-02T07:38:13.973 回答
-1

解决了错误我不知道为什么之前它不起作用..无论如何,谢谢你们的回复!

于 2012-04-02T07:51:02.900 回答