2017-09-22 4 views
-1

디버깅 할 때 제품 및 하위 범주 링크가 제대로 작동하지만 카테고리는 목록을 표시하지만 각 항목 중 하나를 클릭하여 각 항목을 표시하면 표시되지 않습니다. 아무것도.ASP.NET MVC 5 Traditional Routing

여기가 내 ProductsController.cs입니다. 내가 가지고있는 RouteConfig.cs에

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

:

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' 경로가 활성화 될 때 표시되는 코드 사용 /보기에 대해 더 자세히 설명해 주어야합니까? (즉, "그 중 하나를 클릭하면 ..."모호합니다) – jhenderson2099

답변

0

귀하의 ProductsbyCategorybyPageProductsbySubCategorybyPage 덮어 씁니다. ASP.NET이 들어오는 URL을 구문 분석하려고하면 찾기 일치로 끝나고 Products/A/Page3과 같은 URL은 ProductsbySubCategorybyPage 경로를 통해 전달됩니다. 라우팅 모듈은 A을 하위 카테고리 또는 카테고리로 선호하는지 알 수 없습니다. 고유 한 경로 마스크를 사용하려면 RegisterRoutes 메소드를 리팩토링해야합니다. 예를 들어 Products/SubCategory/{subcategory}Products/Category/{category}과 같습니다.

+0

user3476013 문제가 해결되었습니다. 고맙습니다. – RochaCarter07