Joper
Joper

Reputation: 8209

Map custom route in ASP.NET MVC

I have such route mapping in Global.ascx:

routes.MapRoute(
               "Help", // Route name
               "Help", // URL with parameters
               new { controller = "Home", action = "Help", id = UrlParameter.Optional } // Parameter defaults
            );

So when user typed http://mysite.com/Help he will get a response From Home.Help action.

But if i try to call that route with parameter id=something http://mysite.com/Help/something I am getting an error The resource cannot be found.

How could i fix that?

Upvotes: 2

Views: 1231

Answers (1)

Russ Cam
Russ Cam

Reputation: 125488

You need an {id} route value token in the URL pattern of the route.

routes.MapRoute(
    "Help", // Route name
    "Help/{id}", // URL with parameters
    new { controller = "Home", action = "Help", id = UrlParameter.Optional } // Parameter defaults
);

Upvotes: 5

Related Questions