1 routes.MapRoute( 2 "Default", // 路由名称 3 "{controller}/{action}/{id}/{lastPageIndex}/{isAsc}/{pageIndex}/{pageSize}/{lastOrderField}/{orderField}", // 带有参数的 URL 4 new 5 { 6 controller = Constants.SiteController, 7 action = "Index", 8 id = 0, 9 lastPageIndex = 0, 10 isAsc = "false", 11 pageIndex = 1, 12 pageSize = 10, 13 lastOrderField = "lastOrderField", 14 orderField = UrlParameter.Optional 15 } // 参数默认值
1 $.ajax({ 2 type: 'POST', 3 url: "/isoftstone/PurchaseTable/", 4 data: { OrderNo: no, Purchaser: buyer, Customer: customer, DateFrom: dateFrom, DateTo: dateTo, chkPub: pubP, chkConfirm: pubC, chkDecline: pubD, chkTimeout: pubT }, 5 dataType: "html", 6 async: true, 7 success: function (data) 8 { 9 $("#resultTable").html(data); 10 if(nowIndex.length>0 ) 11 { 12 $("#lblPageIndex").text(nowIndex); 13 } 14 } 15 });
翻页后视图url变成
http://localhost:3789/isoftstone/PurchaseOrderAll/0/0/false/2
然后ajax获取分部视图时:
http://localhost:3789/isoftstone/PurchaseOrderAll/0/0/false/2isoftstone/PurchaseTable".
返回了:
以下各节已定义,但尚未为布局页“~/views/shared/_layout_ajax.cshtml”呈现:“leftsider”。呈现:“leftsider”
问题应该是出在路由规则上吧,老项目。。
var rootUrl="@Url.Content("~")";
部署IIS后,每次请求直接在js中获取网站根目录,在加上Controller 和Action 就可以得到ajax post的正确 url 了;
之前的报错:以下各节已定义,但尚未为布局页“~/views/shared/_layout_ajax.cshtml”呈现:“leftsider”。呈现:“leftsider”
就解决了;