2011-03-17 110 views
0

我正在使用ASP.NET MVC 3並遵循教程http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-csASP.NET MVC 3基本路由問題

我正在註冊功能並嘗試使用路由。所以典型的情況是:

  1. 當用戶想要註冊時,他會被帶到/帳戶/註冊。
  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 }); 

什麼我不能在這裏抓?

回答

1

您的路線參數稱爲id,所以:

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

,或者如果你想將其更改爲msg

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

變化從你的方法的參數id並創建一個GET方法/帳戶/註冊行動

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

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

嘿安德魯,是不是第二個方法所需的一切? – DavidS 2011-03-18 07:11:48

+0

是的,我認爲我錯誤地閱讀了你的問題 – 2011-03-18 08:23:29