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 o开发者_StackOverflowne 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
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.
精彩评论