Asp.Net MVC中,Url.Action生成的错误URL如何修正?
- 内容介绍
- 文章标签
- 相关推荐
本文共计281个文字,预计阅读时间需要2分钟。
我搜索并阅读了我在这里和谷歌找到的所有相关问题,似乎找不到解决方案。Rout的问题可能像这样:`routes.MapRoute(Admin-Change Password, Admin/ResetPassword/{UserId}, new { controller=Admin, action=ResetPassword });`
Rout的问题是这样的:
routes.MapRoute("Admin - Change Password", "Admin/ResetPassword/{UserId}", New With {.controller = "Admin", .action = "ResetPassword", .UserId = ""})
它生成的Url是:
/管理/ UserAdmin
这是url.action所在的页面.不知道这是否重要.
当我使用路由调试器时,它显示了Url我希望它生成与我在地址栏中输入的URL匹配.
True Admin / ResetPassword / {UserId} controller = Admin,action = ResetPassword,userId =
它匹配的唯一其他路线是:
True {controller} / {action} / {id} controller = Home,action = Index,id =
真{* catchall}(null)
{controller} / {action} / {id}路由是最后一个路由,因此它不应该干扰.
有任何想法吗?
编辑:帮助者的代码:
<%Url.Action("ResetPassword", "Admin", new with {.UserId= u.userId}) %> 不要使用Action / ActionLink为命名路由生成URI.请改用RouteLink / RouteUrl.它更快,它永远不会找到你想要的路线.完整解释 here.
本文共计281个文字,预计阅读时间需要2分钟。
我搜索并阅读了我在这里和谷歌找到的所有相关问题,似乎找不到解决方案。Rout的问题可能像这样:`routes.MapRoute(Admin-Change Password, Admin/ResetPassword/{UserId}, new { controller=Admin, action=ResetPassword });`
Rout的问题是这样的:
routes.MapRoute("Admin - Change Password", "Admin/ResetPassword/{UserId}", New With {.controller = "Admin", .action = "ResetPassword", .UserId = ""})
它生成的Url是:
/管理/ UserAdmin
这是url.action所在的页面.不知道这是否重要.
当我使用路由调试器时,它显示了Url我希望它生成与我在地址栏中输入的URL匹配.
True Admin / ResetPassword / {UserId} controller = Admin,action = ResetPassword,userId =
它匹配的唯一其他路线是:
True {controller} / {action} / {id} controller = Home,action = Index,id =
真{* catchall}(null)
{controller} / {action} / {id}路由是最后一个路由,因此它不应该干扰.
有任何想法吗?
编辑:帮助者的代码:
<%Url.Action("ResetPassword", "Admin", new with {.UserId= u.userId}) %> 不要使用Action / ActionLink为命名路由生成URI.请改用RouteLink / RouteUrl.它更快,它永远不会找到你想要的路线.完整解释 here.

