我有以下RouteConfig
:
routes.MapRoute(
"CompareDevicesByPage",
"ComparedDevices/{id}/{sortingType}/{sortingDirection}/{searchText}/{page}",
new { controller = "Compare", action = "Page", id = UrlParameter.Optional, sortingType = UrlParameter.Optional, sortingDirection = UrlParameter.Optional, searchText = UrlParameter.Optional, page = UrlParameter.Optional }
);
routes.MapRoute(
"ManufacturerDevices",
"Manufacturer/{objectName}/{id}/{title}/{sortingType}/{sortingDirection}/{searchText}/{page}",
new { controller = "Manufacturer", action = "Devices", title = UrlParameter.Optional, page = UrlParameter.Optional, sortingType = UrlParameter.Optional, sortingDirection = UrlParameter.Optional, searchText = UrlParameter.Optional }
);
每当我使用Url.RouteUrl
时,它都会返回null。
Url.RouteUrl("CompareDevicesByPage", new { id = 0, page = 1, sortingType = (short)DevicesSortingEnum.Popular, sortingDirection = (int)SortDirection.Descending, searchText = "" })
出了什么问题?
答案 0 :(得分:0)
我发现了问题,
我必须将地图路线更改为以下内容:
routes.MapRoute(
"CompareDevicesByPage",
"ComparedDevices/{id}/{sortingType}/{sortingDirection}/{page}/{searchText}",
new { controller = "Compare", action = "Page", id = UrlParameter.Optional, sortingType = UrlParameter.Optional, sortingDirection = UrlParameter.Optional, searchText = UrlParameter.Optional, page = UrlParameter.Optional }
);
routes.MapRoute(
"ManufacturerDevices",
"Manufacturer/{objectName}/{id}/{title}/{sortingType}/{sortingDirection}/{page}/{searchText}",
new { controller = "Manufacturer", action = "Devices", title = UrlParameter.Optional, page = UrlParameter.Optional, sortingType = UrlParameter.Optional, sortingDirection = UrlParameter.Optional, searchText = UrlParameter.Optional }
);