2017-09-22 112 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