ASP.NET MVC Routing

Posted by creativeincode on Stack Overflow See other posts from Stack Overflow or by creativeincode
Published on 2010-05-27T11:14:11Z Indexed on 2010/05/27 11:21 UTC
Read the original article Hit count: 266

My website uses categories and sub-categories.

I'd like the follow mapping:

/Category/Fruit

/Category/Fruit/Apples

But if I use the below:

routes.MapRoute( 
            "Category", // Route name 
            "Category/{category}/{subcategory}", // URL with parameters 
            new { controller = "Entity", action = "Category" } // Parameter defaults 
        );

I get a 404 for /Category/Fruit however /Category/Fruit/Apples works ok. I'd like /Category/Fruit to work as well but I can't add another route with the same name. How do I get around this?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2