views:

37

answers:

3

i have this url http://localhost:17643/category/1/Home/Arts/

It shoud redirect to home/index?idCategory=1

Instead i get a page not found.

the RouteRegistrar is:

  routes.MapRoute(
            "Category",
            "category/{idCategory}/{categories}",
            new { controller = "home", action = "index", idCategory = "" }
        );
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }  // Parameter defaults
        );

Thank you

A: 
 routes.MapRoute(
            "Category",
            "home/index/{idCategory}",
            new { controller = "home", action = "index", idCategory= "" }
        );

This will redirect you to /home/index?idCategory=1

šljaker
+3  A: 

Try changing adding the wildcard to the categories bit:

  routes.MapRoute( 
            "Category", 
            "category/{idCategory}/{*categories}", 
            new { controller = "home", action = "index", idCategory = "" } 
        ); 

This will allow everything beyond the categories part to be included in the category.

And in case you don't already know the first rule of Routing is:

The first matching route found will be used all proceeding routes will be ignored so make sure you put your most specific routes first.

BritishDeveloper
+1  A: 

I'd strongly suggest looking at this routing debugger by Phil Haack. It's invaluable when trying to work out why your routing isn't operating as expected.

Lazarus