Asp.net mvc 3 ASP.NET MVC 3基本路由问题

Asp.net mvc 3 ASP.NET MVC 3基本路由问题,asp.net-mvc-3,asp.net-mvc-routing,Asp.net Mvc 3,Asp.net Mvc Routing,我正在使用ASP.NET MVC 3,并遵循这里的教程 我正在开发注册功能,并试图利用路由。因此,典型的情况是: 当用户想要注册时,他会被带到/Account/SignUp 成功注册后,他会被重定向到/Account/SignUp/Successful 我原以为这很简单,但“Successful”参数从未在控制器的注册方法中传递 public ActionResult SignUp(string msg) { // Do some checks on whether msg is

我正在使用ASP.NET MVC 3,并遵循这里的教程

我正在开发注册功能,并试图利用路由。因此,典型的情况是:

  • 当用户想要注册时,他会被带到/Account/SignUp
  • 成功注册后,他会被重定向到/Account/SignUp/Successful 我原以为这很简单,但“Successful”参数从未在控制器的注册方法中传递

     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 });
    

    我在这里没有掌握什么?

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

    public ActionResult SignUp(string id)
    {
        ...
    }
    
    如果需要,也可以将其更改为
    msg

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

    将参数从方法更改为
    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
    }
    

    嘿,安德鲁,第二种方法不就够了吗?