如何使用window.location.href =在ActionResult方法的url中附加数据

时间:2016-06-26 07:35:34

标签: javascript jquery ajax asp.net-mvc url-routing

我无法理解如何使用window.location.href = '/Product/Success/'+data.OrderTrackNo+'';使用ajax带来数据,但使用window.location.href带来数据有些不同,所以我不能

我的jquery代码是

 var cartid = $("#userid").text();
                var email = $('#youremail').val();
                var name = $("#yourname").val();
                var phoneno = $("#yourphoneno").val();
                var ship = $("#thtshipinfo").val();
                var pin = $("#txtpin").val();

                $.ajax({
                    url: '/Product/cartSave',
                    method: 'post',
                    dataType: 'json',
                    data: { 'cartid': cartid, 'name': name, 'email': email, 'phoneno': phoneno, 'Address': ship, 'pin': pin },
                    success: function (data) {

                        alertify(data.OrderTrackNo);
                        window.location.href = '/Product/Success/'+data.OrderTrackNo+'';

                    },
                    error: function (data) {
                        alert(Error);
                    }
                })

和Actionresult代码是

  public ActionResult success( int orderno)
    {
        DeliveryLocationCookies();
        loginMaintain();
        cartMaintain();
        ViewBag.orderno = orderno;
        return View();

    }

产品控制器中的此动作

1 个答案:

答案 0 :(得分:0)

您应该在查询字符串上定义变量名称,如下所示:

window.location.href = "/Product/Success/?orderno=" + data.OrderTrackNo;