将路由映射到同一个控制器操作

时间:2009-08-07 19:37:05

标签: asp.net asp.net-mvc controller

我只想要一个控制器动作来处理所有GET。如何绘制路线以进行此操作?

2 个答案:

答案 0 :(得分:2)

routes.MapRoute("AllGETs",
    "{*any}",
    new { Controller = "YourController", Action = "YourAction" },
    new { HttpMethod = new HttpMethodConstraint("GET") }
);

答案 1 :(得分:0)

我实际上最终做到了这一点,似乎做了我需要的事情:

routes.MapRoute(
    // Route name
    "Default",             
    // URL with parameters
    "{controller}/{id}",   
    // Parameter defaults
    new {controller = "Home", action = "GenericPostHandler", id = "" }
);
相关问题