Eden
Eden

Reputation: 709

Routing without a controller and action name

I've a very basic ASP.NET MVC application that uses the default routing. Now I need to route all the requests that comes with out a specific URL to one action with a single parameter.

Examples:

www.myapp.com/2374982

www.myapp.com/3242342

should be routed to the same action:

public ActionResult ViewById(int id)

Thanks, Eden

Upvotes: 1

Views: 2474

Answers (1)

Mike Koder
Mike Koder

Reputation: 1928

Just define the route without {controller}/{action} part

routes.MapRoute("ById", "{id}", new { controller = "Home", action = "ViewById"}, new{id = @"\d+"});

The last parameter is constraint, which makes sure that the id is a number.

Upvotes: 4

Related Questions