我已經定義自定義路由路由到特定的URL從jQuery的負載
routes.MapRoute(
name: "ListRoute",
url: "List/{id}",
defaults: new { controller = "List", action = "Index", id = UrlParameter.Optional, type = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, type = UrlParameter.Optional }
);
,並試圖通過jQuery
$('#dvPartialFeatured').load("@Url.Action("DetailList", "List")");
這裏載入我的部分頁面是我在ListController控制器:
public ActionResult Index(string id)
{
return View();
}
public PartialViewResult DetailList(int id, int type)
{
var objSearchModels = new SearchModels()
{
SubCategory = id,
Type = type
};
return PartialView("~/Views/ProductListing/_PartialProductListing.cshtml", ProductListingService.PopulateSearchList(objSearchModels));
}
但它重定向到Index,我甚至試過用
$('#dvPartialFeatured').load("@Url.HttpRouteUrl("Default", new { Controller = "List", Action = "DetailList" })", {id:1, type:2});
然而,當我刪除自定義路線ListRoute它做工精細
您的鏈接不包含'type'屬性('id'可以省略,因爲它在路由中是可選的),因此它與方法的簽名不匹配,因此您將被重定向到默認值。 –
我添加類型作爲可選的,但仍然是結果相同 – brykneval
不需要''action =「DetailList」'''而不是''action =「Index」'' –