Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need this types of urls in MVC4.

www.example.com/catagories/man/jeans/index
www.example.com/catagories/man/formalpants/index

How can I do this??
Posted

1 solution

This depends some on how you're accessing your controllers. MVC uses Routes to track the items in a URL, and you can separate them out in a few ways. If you're using a categories area, you could pass the other elements as arguments.

Assuming categories is an Area, man is ManController (kinky) and jeans/formalpants are arguments, you could put the following into the Area routeconfig:

C#
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapRoute(
            "Categories",
            "categories/{controller}/{type}/{action}
             new { controller = "Man", action = "Index", type = 'jeans' });
    }
}


MVC will automatically resolve the controller and action elements.

If you need more information, have a look at:
https://msdn.microsoft.com/en-us/library/cc668201.aspx[^]
 
Share this answer
 
Comments
Avik Ghosh22 30-Jan-15 7:28am    
Thank u..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900