1

我有一个观点:

 <table id="cartbox">
            <thead>
                <tr>
                    <th>Tên hàng</th>
                    <th>Số lượng</th>
                    <th>Đơn giá</th>
                    <th colspan="2" style="width:70px">Thành tiền</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var line in Model.Cart.Lines)
                {
                    <tr>

                        <td>@line.Product.Name
                        </td>
                        <td class="qty">@Html.DropDownList("Quantity", new SelectList(ViewBag.Items as System.Collections.IList, "Value", "Text", line.Quantity))</td>
                        <td style="color:#3A9504;margin-left:3px" class="price">@string.Format("{0:00,0 VNĐ}", line.Product.Price)</td>
                        <td class="subtotal">@string.Format("{0:00,0 VNĐ}", (line.Quantity * line.Product.Price))</td>
                        <td align="center" style="width:10px"><a href="@Url.Action("RemoveFromCart","Cart",new{ProID= line.Product.ProductID, returnUrl= Request.Url.PathAndQuery})"><img src="@Url.Content("~/Content/Images/delete.png")" style="padding-right:10px" /></a></td>
                    </tr>
                }

            </tbody>
            <tfoot>
                <tr style="border-top-style:solid;border-top-color:#DFDFDF;border-top-width:1px;">
                    <td colspan="3" align="right" style="border-right-color:#808080;border-right-style:solid;border-right-width:1px;text-align:right"><b>Tổng tiền:</b></td>
                    <td style="text-align: center"><b>@string.Format("{0:00,0 VNĐ}", Model.Cart.ComputeTotalValue())</b></td>
                    <td></td>
                </tr>
            </tfoot>
        </table>

当用户更改下拉列表上的数量时,我应该使用哪个 jquery ajax 函数来更新小计和总计:

function CalValue() {
$("#select").change(function () {
    var quantity = $(this).val();
    var fprice = $(this).closest("tr").find("td[class^=price]").html();
    var price = fprice.replace(/[,\s(VNĐ)]/g, '')
    var fsubtotal = parseInt(quantity) * parseInt(price);
    var subtotal = 
    $(this).closest("tr").find("td[class^=subtotal]").html(subtotal);
});

}

这个功能的问题是在我刷新页面后,页面返回原始值,没有任何变化。或者

   function UpdateValue() {
    $(document.body).on("change", ".Quantity", function () {
        var ProID = $(this).attr("data");
        var Quatity = $(this).val();
        $.ajax({
            type: "GET", url: "/Cart/UpdateValue",
            data: { ProID: ProID, quantity: Quatity },
            success: function (data) {
                $("#cartbox").html(data);
            }
        }
            );
        $.ajaxSetup({
            cache: false
        });
    });
}

这个问题是它返回一个新视图,但下拉列表在视图中重复。

任何人都可以告诉我如何控制或使用哪种方法?请。

4

1 回答 1

0

如果您想在客户端保存信息,您有以下选项:

  1. 将其发送到服务器并将其存储在会话中,并在视图渲染期间使用此信息
  2. 在客户端使用本地存储,重新加载后检查本地存储是否有这些数据并正确使用它们
于 2013-08-01T04:22:22.470 回答