Developer
Developer

Reputation: 888

Custom Name for URL's in Asp.net MVC4

I am working with URL's in MVC4, as my question is can we give name for URL's in MVC4 like for example user want to go "Ask Question' section, then on click website redirected to 'stackoverflow.com/questions/ask'.

But I want to show user as 'stackoverflow.com/questions' only. I want to name like for every URL's action. is this possible in MVC 4.

Please help me anyone. Thanks in Advance.

Upvotes: 1

Views: 62

Answers (1)

WorkSmarter
WorkSmarter

Reputation: 3808

The route will handle all "stackoverflow.com/questions" URL requests. Make sure this route is placed above the catchall default route. If not, this route will never be triggered. Additional route customization could be found here.

routes.MapRoute(
    name: "questions",
    url: "questions/{id}",
    defaults: new
    {
        controller = "questions",
        action = "ask",
        id = UrlParameter.Optional
    }
);

Upvotes: 2

Related Questions