2016-03-13 64 views
0

所以夥計們,我只是創建了一個_Login部分而不是Login視圖,並在我的_Layout中渲染了局部視圖。局部視圖顯示在Modal中,直到所有事情都看起來不錯!但是,無論何時只要點擊登錄(登錄)按鈕,頁面就會重新加載並且什麼都不會發生,儘管我期望像電子郵件字段這樣的錯誤不能爲空或者用戶不存在,但意外的是沒有任何事情發生,並且頁面刷新。 以下是_Login部分的代碼。我怎樣才能防止頁面刷新(重新加載),同時按asp.net mvc身份登錄按鈕?

@model Hire.af.WebUI.Models.LoginViewModel 

<div class="modal-body"> 
    <!--Social Media Login Links--> 
    <div class="form-group row login-socical"> 
     <div class="col-sm-9 col-sm-offset-3"> 
      <div class="button_socical fb"> 
       <i class="fa fa-facebook-square"> </i> 
       <em class="fa-facebook-square">Login with Facebook</em> 
      </div> 
      <div class="button_socical gg"> 
       <i class="fa fa-google-plus"> </i> 
       <em class="fa-google-plus">Login with Google</em> 
      </div> 
      <div class="button_socical linkedin"> 
       <i class="fa fa-linkedin-square"> </i> 
       <em class="fa-linkedin-square">Login with LinkedIn</em> 
      </div> 
     </div> 
    </div> 

    <!--Login Form--> 
    <form class="noo-ajax-login-form form-horizontal"> 

     @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 
     { 
      @Html.AntiForgeryToken() 
      <hr /> 
      @Html.ValidationSummary(true, "", new { @class = "col-sm-3" }) 
      <div class="form-group row"> 
       @Html.LabelFor(m => m.Email, new { @class = "col-sm-3 control-label" }) 
       <div class="col-sm-9"> 
        @Html.TextBoxFor(m => m.Email, new { @class = "log form-control", @placeholder="Email OR Username" }) 
        @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" }) 
       </div> 
      </div> 
      <div class="form-group row"> 
       @Html.LabelFor(m => m.Password, new { @class = "col-sm-3 control-label" }) 
       <div class="col-sm-9"> 
        @Html.PasswordFor(m => m.Password, new { @class = "pwd form-control", @placeholder="Password" }) 
        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" }) 
       </div> 
      </div> 
      <div class="form-group"> 
       <div class="col-md-offset-2 col-md-10"> 
        <div class="checkbox"> 
         @Html.CheckBoxFor(m => m.RememberMe) 
         @Html.LabelFor(m => m.RememberMe) 
        </div> 
       </div> 
      </div> 

      <!--Remember Me Checkbox--> 
       <div class="form-actions form-group text-center"> 
        <button type="submit" class="btn btn-primary">Sign In</button> 
        <div class="login-form-links"> 
         <span><a href="#"><i class="fa fa-question-circle"></i> Forgot Password?</a></span> 
         <span> 
          Don't have an account yet? 
          <a href="#" class="member-register-link" data-rel="registerModal"> 
           @Html.ActionLink("Register Now", "Register") <i class="fa fa-long-arrow-right"></i> 
          </a> 
         </span> 
        </div> 
       </div> 

      @* Enable this once you have account confirmation enabled for password reset functionality 
      <p> 
       @Html.ActionLink("Forgot your password?", "ForgotPassword") 
      </p>*@ 
     } 


    </form> 
</div> 

以下是我如何在_Layout中渲染這個部分。

<div class="memberModalLogin modal fade" id="userloginModal" tabindex="-1" role="dialog" aria-hidden="true"> 
     <div class="modal-dialog modal-member"> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
         <span aria-hidden="true">&times;</span> 
        </button> 
        <h4 class="modal-title">Login</h4> 
       </div> 
       <!--Login Partial Goes Here--> 
       @Html.Partial("_Login") 
      </div> 
     </div> 
    </div> 

任何幫助,將不勝感激。

回答

2

你有嵌套的表格,這是無效的HTML和不支持。從局部視圖中刪除外表格

<form class="noo-ajax-login-form form-horizontal"> // remove this and its closing tag 
    @using (Html.BeginForm(.... 
相關問題