0

我单击按钮,但参数没有传递到我的视图。按钮将正常工作,我刚刚将它放在警报消息上将显示警报消息。我的看法如下

       <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-ui-1.8.20.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"/>               
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                   $('#AddToCard').click(function () {
                    var ProductID = $('#txtproductID').val();
                    var Quantity = $('#txtQuantity').val();
                    var NetAmt = $('#txtNetAmt').val();
                    var ProName = $('#txtPN').val();
                    alert("ID="+ProductID+"QTY=" + Quantity+"NETAMT=" + NetAmt+"Name=" + ProName);
                    $.ajax({
                        type: "POST",
                        url: '../Home/AddOrderItem',
                       data: { productCode: ProductID, quantity: Quantity, NAMT: NetAmt, PName: ProName },

                        success: function (data) {
                             if (data) {
        //                        alert("Added To your Card");
                            }
                      }
                    });
                });


            });
        </script>

我的控制器是

       public void AddOrderItem(Int64 productCode, int quantity, decimal NAMT, string PName)
            {
                //adds an item to the current order
                OrderDO order = (OrderDO)Session["Order"];
                decimal TotAmt = quantity * NAMT;
                order.Items.Add(new OrderItem(productCode, quantity,NAMT,PName,TotAmt));
                Session["Order"] = order;
              }
4

1 回答 1

0

要将结果从控制器返回到视图,您应该返回 Json 对象。

public ActionResult AddOrderItem(Int64 productCode, int quantity, decimal NAMT, string PName)
{
    //adds an item to the current order
    OrderDO order = (OrderDO)Session["Order"];
    decimal TotAmt = quantity * NAMT;
    order.Items.Add(new OrderItem(productCode, quantity,NAMT,PName,TotAmt));
    Session["Order"] = order;

    return Json(order, JsonRequestBehavior.AllowGet);
}
于 2013-02-11T07:30:28.423 回答