2014-09-10 30 views
1

我有一個問題,我的表單提交到我的控制器中的特定方法。使用MVC提交表單4不觸發我的BeginForm指定的動作

當我提交按鈕,用戶點擊,就會觸發Index作用,忽略了在我的BeginForm

什麼是與我的形式問題指定我ValidateLogin行動?

HTML

@model Login.Models.Autenticacao 
@{ 
    Layout = null; 
} 

<!DOCTYPE html> 

<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Index</title> 
    <link href="~/Content/bootstrap.css" rel="stylesheet" /> 
    <link href="~/Content/endless.css" rel="stylesheet" /> 
    <script src="~/Scripts/jquery-1.8.2.js"></script>  
</head> 
    <body> 
      <div id="formAutenticacao"> 
       <div class="pace pace-inactive"> 
        <div data-progress="99" data-progress-text="100%" style="width: 100%;" class="pace-progress"> 
         <div class="pace-progress-inner"></div> 
        </div> 
        <div class="pace-activity"></div> 
       </div> 
       <div class="login-wrapper"> 
        <div class="text-center"> 
         <h2 class="fadeInUp animation-delay8" style="font-weight: bold"> 
          <img src="~/Images/Horizonta_com_S.png" /> 
         </h2> 
        </div> 
        <div class="login-widget animation-delay1"> 
         <div class="panel panel-default"> 
          <div class="panel-body"> 
            @using (Html.BeginForm("ValidateLogin", "Login", FormMethod.Post)) 
            { 
             <div class="form-group"> 
              <label>User</label> 
              @Html.TextBoxFor(m => m.UserName, new {placeholder = "Type user name", Class = "form-control input-sm bounceIn animation-delay2"}) 
             </div> 
             <div class="form-group"> 
              <label>Password</label> 
              @Html.PasswordFor(m => m.Password, new {placeholder = "Type the password", Class = "form-control input-sm bounceIn animation-delay4"}) 
             </div> 
             <div class="seperator"></div> 
             <hr> 

             <input type="submit" value="Go!" /> 
            } 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
      <iframe id="iframePrincipal" height="0" width="100%" frameborder="0"></iframe> 
</body> 
</html> 

登錄控制器

public ActionResult Index() 
    {    
     return View(); 
    } 

    [HttpPost] 
    public ActionResult ValidateLogin(Autenticacao form) 
    { 
     return View(); 
    } 

路線

public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 

型號

public class Autenticacao 
{ 
    [Required] 
    public virtual string UserName { get; set; } 

    [Required] 
    public virtual string Password { get; set; } 
} 

螢火蟲

FYI:我翻譯的我Action的名字在這個問題上更好地理解。

enter image description here

+1

什麼是螢火蟲說什麼?請求去了哪裏? – WeSt 2014-09-10 12:38:57

+1

您是否檢查生成的html中的表單標記(使用瀏覽器的查看源)呈現的路徑? – 2014-09-10 12:39:31

+0

@WeSt在firebug中說'重新加載頁面以獲取:http:// localhost:53059/Login/ValidateLogin'的源代碼,並且所有參數都已通過。但我的方法ValidateLogin只是應該返回一個View。 – 2014-09-10 12:44:11

回答

1

發現我的錯誤。

在web.config中我註釋以下行

<authorization> <deny users="?" /> </authorization>