user1155788
user1155788

Reputation: 51

custom route not fails for me

I create a simple MVC3 application and then I add in the following route to see if such a custom route works.

routes.MapRoute("self",
                "route/{message}",
                new { controller = "Route", action = "Message" }
                );

And I use the following url http://localhost:2554/Route/message but it doesn't work.

Upvotes: 0

Views: 37

Answers (1)

tvanfosson
tvanfosson

Reputation: 532435

What does your Message action look like? Does it take any parameters? What type are they?

I suspect that you really want something that looks like:

 routes.MapRoute("self",
            "route/{message}",
            new { controller = "Route", action = "Message", message = UrlParameter.Optional }
            );

with an action that looks like

  public class RouteController
  {
       [HttpGet]
       public ActionResult Message( int message )
       {
           ...
       }
  }

so that the URL looks like http://localhost:2554/route/1 (or some other id)

Note that the order in which the routes are specified is important. This needs to come before the default route to be effective.

Upvotes: 2

Related Questions