MVC 2.0 路由问题 - 无法识别 Url 参数
在我的 AccountController 类中,我有以下内容:
public ActionResult Verification(string userGuid)
{
Debug.WriteLine(userGuid);
...
在我的 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
);
In my AccountController class I have the following:
public ActionResult Verification(string userGuid)
{
Debug.WriteLine(userGuid);
...
In my global.asax I have:
routes.MapRoute(
"AccountVerification",
"{controller}/{action}/{userGuid}",
new { controller = "Account", action = "Verification", userGuid = UrlParameter.Optional }
);
When I go to http://localhost/Account/Verification/123 ... theres no debug output... its not recognizing the parameter - which is my problem. Not sure what I'm missing.
I do want this parameter to be optional... if its not set then I return a different view.
Edit:
When I place a Debug.WriteLine("hello world");
in the Verification function, it does output it so the routing appears to go to the correct function.
Edit Again:
The default controller is still present but I wouldn't think it would hit that route since it uses a different controller / action
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您给我们的路线应该与此匹配 - 您在上面定义了哪些其他路线?它可能会通过不同的路线被拾取。
The route you have given us should match this - what other routes have you defined above it? It may be being picked up by a different route.
RouteDegguer 将帮助识别正在选择的路由向上。
The RouteDegguer will help identify which routes are being picked up.
把这个定义放在最上面,看看是否还不行。调试路由的第一步
Put this definition at the top and see if it still doesn't work. first step to debugging routes