0

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

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.