代码之家  ›  专栏  ›  技术社区  ›  Chris Klepeis

MVC 2.0路由问题-无法识别URL参数

  •  2
  • Chris Klepeis  · 技术社区  · 16 年前

    在我的AccountController类中,我有以下内容:

    public ActionResult Verification(string userGuid)
    {
    
        Debug.WriteLine(userGuid);
    ...
    

    在my global.asax中,我有:

    routes.MapRoute(
        "AccountVerification", 
        "{controller}/{action}/{userGuid}", 
        new { controller = "Account", action = "Verification", userGuid = UrlParameter.Optional }
    );
    

    当我去 http://localhost/Account/Verification/123 …没有调试输出…它无法识别参数——这是我的问题。不知道我错过了什么。

    我希望这个参数是可选的…如果它没有设置,那么我返回一个不同的视图。

    编辑 : 当我放置一个 Debug.WriteLine("hello world"); 在验证函数中,它会输出它,因此路由似乎转到了正确的函数。

    再次编辑 : 默认控制器仍然存在,但我不认为它会命中该路由,因为它使用不同的控制器/操作

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
    
    3 回复  |  直到 16 年前
        1
  •  4
  •   David M    16 年前

    你给我们的路线应该与之匹配-你在上面定义了哪些其他路线?它可能被另一条路线接走。

        2
  •  1
  •   gnome    16 年前

    这个 RouteDegguer 将有助于确定正在取货的路线。

        3
  •  0
  •   BritishDeveloper    16 年前

    把这个定义放在最上面,看看它是否仍然不起作用。调试路由的第一步