2 g420607387 G420607387 于 2015.05.27 14:29 提问

关于MVC4路由限制Ajax传参问题!!!!
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var productDetailRoute = routes.MapRoute(
                name: "ProductDetail",
                url: "ProductDetail/{skuID}.aspx",
                defaults: new { controller = "Product", action = "BrowseProduct" },
                constraints: new { skuID = @"\d+" }
            );

            var intRegex = @"\d+";
            routes.Redirect(r =>
            {
                return r.MapRoute(
                        name: null,
                        url: "ProductList.aspx",
                        defaults: new { catagoryID = "001.001", Para0 = "0", Para1 = "0", Para2 = "0", Para3 = "0", Para4 = "0", Para5 = "0", Para6 = "0", Para7 = "0", pageNo = 1 }
                );
            }, true).To(routes.MapRoute(
                name: "ProductList",
                url: "ProductList/{catagoryID}-{Para0}-{Para1}-{Para2}-{Para3}-{Para4}-{Para5}-{Para6}-{Para7}-{pageNo}.aspx",
                defaults: new { controller = "Product", action = "ProductList"},
                constraints: new { catagoryID = "(" + intRegex + @"\.)*?" + intRegex, Para0 = intRegex, Para1 = intRegex, Para2 = intRegex, Para3 = intRegex, Para4 = intRegex, Para5 = intRegex, Para6 = intRegex, Para7 = intRegex, pageNo = intRegex}
            ));

            routes.Redirect(r =>
            {
                return r.MapRoute(null, "", new { action = "Index" });
            }, true).To(routes.MapRoute(
                name: "Default",
                url: "{action}.aspx",
                defaults: new { controller = "Product" }
            ));
        }
  $("#Sea").click(function(){
            var Search = $("#Search").val();
            alert(Search);
            //debugger;
            $.ajax({
                type: "get",
                url: "@SiteConfig.ProductSite/ProductList.aspx?Search=Search",
                jsonpCallback: "__ProductLists__", //回调方法
                dataType: "jsonp",                        //跨域调用数据协议
                data: { Search: Search },   //自定义参数名,值
                success: function (data) {
                    alert("成功");
                },
                error: function () {
                    alert("失败");
                }
                });
        })
        public ActionResult ProductList(string catagoryId, int pageNo, ProductFilterModel filterModel,string Search)
        {  
           // catagoryId = "001.001";   
            pageNo = 1;
            Response.Cache.SetOmitVaryStar(true);           
            var pager = new PagerModel(pageNo, 12);
            //Sear = Request.QueryString["Search"].ToString();
            int MemberType=2;
            if (MemberInfo != null && (MemberInfo.MemberType) != 0)
            {
                MemberType = MemberInfo.MemberType;
            }
            var dt = new ProdSkuProductSystem().SelectProdSkuProductByOptionValueIds(catagoryId, filterModel.ToList(), MemberType, Search, pager); 

目前想通过Ajax 传参数过来,但是仔细检查好像被路由限制了,无法传参,不知道这里路由该怎么改,就大神详解!!!!!

1个回答

caozhy
caozhy   Ds   Rxr 2015.05.27 14:35

下载安装RouteDebugger
访问你的地址,贴出它的运行结果图。
http://www.cnblogs.com/jhxk/articles/2608655.html

G420607387
G420607387 MVC4不行。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片