2011-05-20 195 views
2

您好我用我的代碼這兩條線:asp.net MVC自定義路由

using (Ajax.BeginForm("Login", "Users", new { command = "Login"}, new AjaxOptions() { UpdateTargetId = "divLoginPopupContent" }, new { id = "loginPopup" })) 
{ 
    /// some html with submit button 

    // and also have following: 
    <%= Html.ActionLink("Forgot your password", "Login", "Users", new { command = "ForgotPassword" }, null)%> 
} 

,這是地圖的路線,我有

routes.MapRoute(
       "Users", 
       "Users/{command}", 
       new { controller = "Users", action = "Login" } 
      ); 

,這是控制器的動作:

public ActionResult Login(LoginModel model, string command) 
    { 
      /// some actions 
    } 

但我不知道我在做什麼錯在這裏...我希望ActionLink和BeginForm都被路由到這個控制器動作。

+0

嗯..你面對的是什麼樣的錯誤?我只是使用你的代碼片段,一切看起來不錯..使用actionlink和提交按鈕我正確路由到登錄行動與適當的命令... – rjovic 2011-05-20 12:07:41

+0

因爲我有模型在我的參數,所以它沒有帶我去那個行動.. 。 – 2011-05-20 12:11:30

+0

給我這個錯誤 HTTP 404。您正在查找的資源(或它的一個依賴項)可能已被刪除,更名或暫時不可用。請檢查以下網址並確保它拼寫正確。 – 2011-05-20 12:14:53

回答

2

回答我的問題:

我還沒有確定另一路由集合變量即命令應聲明,這樣

routes.MapRoute(
       "Users", 
       "Users/{command}", 
       new { controller = "Users", action = "Login", 
       command = Parameter.Optional } 
      );