如何将具有QueryString的url路由到Controller的特定ActionResult

时间:2014-11-10 17:51:28

标签: c# asp.net asp.net-mvc-3

我正在使用C#中的ASP.NET MVC 3,我希望将包含QueryString的URL路由到所需的控制器和操作方法。 网址将像localhost:44578/HVAC/?pos=installer我想要路由此。我不知道该怎么做。 我是MVC的新手。

RouteConfig中的默认路由是

routes.MapRoute(
                name: "Default",
                url: "{siteName}/{controller}/{action}/{id}",
                defaults: new { controller = "SeoTree", 
                action = "Index", id = UrlParameter.Optional }
            );

我想创建新的地图路线,将路线路由到Contoller = "SeoTree" ,action ="PositionInAll"

1 个答案:

答案 0 :(得分:2)

只需按照您的意愿绘制路线:

routes.MapRoute("Custom",
    "{controller}/{action}/{pos}",
    new { controller = "seoTree", action = "PositionInAll"},
    new { pos = @"\d+" }
    );