【问题标题】:how to route url having QueryString to specific ActionResult of Controller如何将具有 QueryString 的 url 路由到控制器的特定 ActionResult
【发布时间】:2014-11-10 17:51:27
【问题描述】:

我正在使用 C# 编写 ASP.NET MVC 3,我想将由 QueryString 组成的 URL 路由到所需的控制器和操作方法。 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"

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • jack.the.ripper 还是不行。它正在使用该控制器的默认 ActionResult
    • 那说明你和其他路由有冲突
    • 好吧,我有另一条路线 routes.MapRoute( "State", "{siteName}/{stateName}", new { controller = "SeoTree", action = "Cities" } );跨度>
    • 我没有看到您的路线中定义了任何 stateName,这可能是冲突的原因,也许如果您通过操作更改 stateName 应该可以解决问题!
    • 对不起,我不明白。
    猜你喜欢
    • 2016-07-18
    • 2017-02-22
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多