ASP.NET MVC 3 基本路由问题
我正在使用 ASP.NET MVC 3 并按照此处的教程 http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs。
我正在研究注册功能并尝试使用路由。所以典型的场景是:
- 当用户想要注册时,他会被带到/Account/SignUp。
- 注册成功后,他会被重定向到/Account/SignUp/Successful。
我认为这很简单,但“成功”参数永远不会在控制器的 SignUp 方法中传递。
public ActionResult SignUp(string msg)
{
// Do some checks on whether msg is empty or not and then redirect to appropriate view
}
在 global.aspx.cs 中,我几乎获得了普通路由:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
我在这里未能掌握什么?
I am using ASP.NET MVC 3 and following the tutorial here http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs.
I am working on the sign up functionality and trying to make use of routing. So the typical scenario is:
- When the user wants to sign up, he would get taken to /Account/SignUp.
- Upon succesful sign up, he then gets redirected to /Account/SignUp/Successful.
I thought it would be simple enough but the "Successful" parameter never gets passed in the SignUp method in the controller.
public ActionResult SignUp(string msg)
{
// Do some checks on whether msg is empty or not and then redirect to appropriate view
}
In global.aspx.cs I've got pretty much the vanilla routing:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
What am I failing to grasp here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的路由参数称为
id
,因此:或者如果您愿意,请将其更改为
msg
:Your route parameter is called
id
, so:or change it to
msg
if you want:将方法中的参数更改为
id
并为 /Account/SignUp 操作创建一个 get 方法Change the parameter from your method to
id
and create an get method for the /Account/SignUp action