开发者

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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜