开发者

Routing without a controller and action name

开发者 https://www.devze.com 2022-12-23 05:25 出处:网络
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 parame

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

精彩评论

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