ASP.NET MVC 3 基本路由问题

发布于 2024-10-22 05:08:14 字数 802 浏览 2 评论 0原文

我正在使用 ASP.NET MVC 3 并按照此处的教程 http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs

我正在研究注册功能并尝试使用路由。所以典型的场景是:

  1. 当用户想要注册时,他会被带到/Account/SignUp。
  2. 注册成功后,他会被重定向到/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:

  1. When the user wants to sign up, he would get taken to /Account/SignUp.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-10-29 05:08:14

您的路由参数称为 id,因此:

public ActionResult SignUp(string id)
{
    ...
}

或者如果您愿意,请将其更改为 msg

"{controller}/{action}/{msg}"

Your route parameter is called id, so:

public ActionResult SignUp(string id)
{
    ...
}

or change it to msg if you want:

"{controller}/{action}/{msg}"
执手闯天涯 2024-10-29 05:08:14

将方法中的参数更改为 id 并为 /Account/SignUp 操作创建一个 get 方法

public ActionResult SignUp()
{
  //this is the initial SignUp method
}

[HttpPost]
public ActionResult SignUp(string id)
{
  //User will be redirected to this method
}

Change the parameter from your method to id and create an get method for the /Account/SignUp action

public ActionResult SignUp()
{
  //this is the initial SignUp method
}

[HttpPost]
public ActionResult SignUp(string id)
{
  //User will be redirected to this method
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文