简体   繁体   English

如何使用jQuery MVC 3剃须刀将参数传递给actionreuslt?

[英]how to pass parameters to actionreuslt using jquery mvc 3 razor?

i am new in mvc3 razor my prob is : 我是mvc3剃须刀的新手,我的问题是:

i have this actionResult method that can receive variables from jquery method 我有这个可以从jquery方法接收变量的actionResult方法

why my variables comes NULL 为什么我的变量为NULL

csharp : csharp:

public ActionResult GetOrdersSP(int? StoreId, int? SupplierId)
        {
            bool count = false;

            var model = _storeOrderService.GetStoreSuppOrders(StoreId, SupplierId);

            if (model.Count() > 0)
            {
                count = true;
                return Json(count, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(count, JsonRequestBehavior.AllowGet);
            }
        }

and this is my jquery 这是我的jQuery

$.fn.GetCount = function (data) {
        var storeid = $('#StoreId').val();
        var Supplierid = $('#Supplierid').val();
        if (ValidateCreateOrder('#StoreId', '#Supplierid')) {
            alert(storeid);
            alert(Supplierid);

            $.ajax(
                {
                    url: '<%: Url.Action("GetOrdersSP", "StoreOrder")%>',
                    type: 'json',
                    data: { StoreId: $('#StoreId').val(),
                        SupplierId: $('#SupplierId').val()
                    },
                    success: function (json) {

                        //should popup the modal 
                        alert(true);
                    }
                });
        }
    }

please note that the storeid and supplierid are displayed correctly in the alert 请注意,商店ID和供应商ID在警报中正确显示

thanks 谢谢

I think you need to convert your data to json and parse it on actionResult. 我认为您需要将数据转换为json并在actionResult上进行解析。

See this post Pass a parameter to a controller using jquery ajax 看到这篇文章使用jquery ajax将参数传递给控制器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM