2017-09-22 151 views
-1

當我調試它,產品和子類別鏈接工作正常,但類別顯示我的名單,但當我點擊其中之一,讓我看看每個內的產品,不顯示任何東西。ASP.NET MVC 5傳統路由

這是我的ProductsController.cs。

public ActionResult Index(string category, string subcategory, string search, string sortBy, int? page){... } 

對我有RouteConfig.cs:

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

    routes.MapRoute(
     name: "ProductsCreate", 
     url: "Products/Create", 
     defaults: new { controller = "Products", action = "Create" } 
    ); 

    routes.MapRoute(
     name: "ProductsbySubCategorybyPage", 
     url: "Products/{subcategory}/Page{page}", 
     defaults: new { controller = "Products", action = "Index" } 
    ); 

    routes.MapRoute(
     name: "ProductsbyCategorybyPage", 
     url: "Products/{category}/Page{page}", 
     defaults: new { controller = "Products", action = "Index" } 
    ); 

    routes.MapRoute(
     name: "ProductsbyPage", 
     url: "Products/Page{page}", 
     defaults: new { controller = "Products", action = "Index" } 
    ); 

    routes.MapRoute(
     name: "ProductsbySubCategory", 
     url: "Products/{subcategory}", 
     defaults: new { controller = "Products", action = "Index" } 
    ); 

    routes.MapRoute(
     name: "ProductsbyCategory", 
     url: "Products/{category}", 
     defaults: new { controller = "Products", action = "Index" } 
    );      

    routes.MapRoute(
     name: "ProductsIndex", 
     url: "Products", 
     defaults: new { controller = "Products", action = "Index" } 
    ); 

    routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}", 
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 
} 
+0

您需要提供更多詳細信息當Productsbycategory路由被激活時,顯示的代碼是什麼/ view? (即,「當我點擊其中一個...」時是不明確的) – jhenderson2099

回答

0

ProductsbyCategorybyPageProductsbySubCategorybyPage覆蓋。 當ASP.NET嘗試解析傳入的URL時,它將停止搜索匹配,並且像Products/A/Page3這樣的URL將通過ProductsbySubCategorybyPage路由傳遞。路由模塊不知道你喜歡什麼A是子類別或類別。您需要重構您的RegisterRoutes方法以使用唯一的路由掩碼。例如,像Products/SubCategory/{subcategory}Products/Category/{category}

+0

user3476013問題已解決。非常感謝你。 – RochaCarter07