Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on MVC4 application.My current url is

http://localhost:3251/product/sports/abc[^]


product is my controller name
sports is category
abc is my item with in sports category

but i want like this

http://localhost:3251/sports/abc[^]


how to solve it.Thanks in advance

What I have tried:

i have tried to change it from route config
Posted
Updated 3-Jun-20 2:25am

I'd suggest you to go for URL Rewriting:

Understanding URL Rewriting and URL Attribute Routing in ASP.NET MVC (MVC5) with Examples - Dot Net Stuff[^]
ASP.NET MVC and the new IIS7 Rewrite Module - Scott Hanselman[^]

You can specify the route to your action method as an attribute.


KR
 
Share this answer
 
Hello

Please follow the below links as well:
Customizing Routes in ASP.NET MVC[^]

ASP.NET MVC Routing Overview (C#) | The ASP.NET Site[^]

Thanks
 
Share this answer
 
Use this Link[^] and

You could try inverting the routes definition by placing the more specialized route first. Also, you probably didn't want to hardcode the action name as action but rather use the {action} placeholder:


public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        //routes.MapMvcAttributeRoutes();

    routes.MapRoute(
        name: "Special",
        url: "{action}",
        defaults: new { controller = "Home", action = "LandingIndex" }
    );

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
   }
}
 
Share this answer
 

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