2016-10-04 3 views
0

나는 기본 웹 응용 프로그램 MVC 프로젝트를 사용하고, 그리고 난 모달에서 등록/로그인을 시도하고있다 : 리디렉션없이 부트 스트랩 모달에 로그인/등록하는 방법?

enter image description here

그래서 내가 로그인에 대한 모델을 포함하는 새로운 모델을 만들어 등록

public class LogInRegisterViewModel 
    { 
     public LoginViewModel login { get; set; } 
     public RegisterViewModel register { get; set; } 
    } 

다음 내 레이아웃 페이지에서 내가 로그인에 대한 부분보기와 함께 그 모델을 제공/등록 :

<div class="navbar-collapse collapse"> 
      <ul class="nav navbar-nav">      
       @if (User.Identity.IsAuthenticated) 
       { 
        <li>@Html.ActionLink("MyUploads", "Index", "Tutorials")</li> 
        <li>@Html.ActionLink("Upload", "Create", "Tutorials")</li> 
       } 
      </ul> 

      @Html.Partial("_LoginPartial",model) @*model = new LogInRegisterViewModel()*@ 
     </div> 

모달의 HTML 코드 내 _LoginPartial보기 것은 (? 어쩌면 이건 내 잘못이다), 그리고 (계정 컨트롤러에서 복사) 로그인 및 등록 양식 : 지금

<div class="modal fade" id="myModal" tabindex="-1" role="dialog"> 
     <div class="modal-dialog" role="document"> 
      <div class="modal-content mc"> 
       <div class="modal-body"> 
        <div class="row"> 
         <div class="col-md-6 login-modal"> 
          <section id="loginForm"> 
           @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 
           { 
            @Html.AntiForgeryToken() 
            <h4>Use a local account to log in.</h4> 
            <hr /> 
            @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
            <div class="form-group"> 
             <div> 
              <h5 class="user-name login-labels"><i class="fa fa-user" aria-hidden="true"></i> User Name</h5> 
             </div> 
             <div class="col-md-8 login-input"> 
              @Html.TextBoxFor(m => m.login.UserName, new { @class = "form-control" }) 
              @Html.ValidationMessageFor(m => m.login.UserName, "", new { @class = "text-danger" }) 
             </div> 
            </div> 
            <div class="form-group"> 
             <h5 class="user-password login-labels"><i class="fa fa-lock" aria-hidden="true"></i> Password</h5> 
             <div class="col-md-8 login-input"> 
              @Html.PasswordFor(m => m.login.Password, new { @class = "form-control" }) 
              @Html.ValidationMessageFor(m => m.login.Password, "", new { @class = "text-danger" }) 
             </div> 
            </div> 
            <div class="form-group"> 
             <div class="col-md-10 login-btn"> 
              <input type="submit" value="Log in" class="btn btn-primary" /> 
             </div> 
            </div> 
            @* Enable this once you have account confirmation enabled for password reset functionality 
             <p> 
              @Html.ActionLink("Forgot your password?", "ForgotPassword") 
             </p>*@ 
           } 
          </section> 
         </div> 
         <div class="col-md-6"> 
          @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 
          { 
           @Html.AntiForgeryToken() 
           <h4>Create a new account.</h4> 
           <hr /> 
           @Html.ValidationSummary("", new { @class = "text-danger" }) 
           <div class="form-group"> 
            @Html.LabelFor(m => m.register.FirstName, new { @class = "col-md-2 control-label" }) 
            <div class="col-md-10"> 
             @Html.TextBoxFor(m => m.register.FirstName, new { @class = "form-control" }) 
            </div> 
           </div> 
           <div class="form-group"> 
            @Html.LabelFor(m => m.register.LastName, new { @class = "col-md-2 control-label" }) 
            <div class="col-md-10"> 
             @Html.TextBoxFor(m => m.register.LastName, new { @class = "form-control" }) 
            </div> 
           </div> 
           <div class="form-group"> 
            @Html.LabelFor(m => m.register.ProfileAvatar, new { @class = "col-md-2 control-label" }) 
            <div class="col-md-10"> 
             @Html.TextBoxFor(m => m.register.ProfileAvatar, new { @class = "form-control" }) 
            </div> 
           </div> 
           <div class="form-group"> 
            @Html.LabelFor(m => m.register.Email, new { @class = "col-md-2 control-label" }) 
            <div class="col-md-10"> 
             @Html.TextBoxFor(m => m.register.Email, new { @class = "form-control" }) 
            </div> 
           </div> 
           <div class="form-group"> 
            @Html.LabelFor(m => m.register.Password, new { @class = "col-md-2 control-label" }) 
            <div class="col-md-10"> 
             @Html.PasswordFor(m => m.register.Password, new { @class = "form-control" }) 
            </div> 
           </div> 
           <div class="form-group"> 
            @Html.LabelFor(m => m.register.ConfirmPassword, new { @class = "col-md-2 control-label" }) 
            <div class="col-md-10"> 
             @Html.PasswordFor(m => m.register.ConfirmPassword, new { @class = "form-control" }) 
            </div> 
           </div> 
           <div class="form-group"> 
            <div class="col-md-offset-2 col-md-10"> 
             <input type="submit" class="btn btn-default" value="Register" /> 
            </div> 
           </div> 
          } 
         </div> 

        </div> 
        <div class="modal-footer"> 
         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
        </div> 
       </div><!-- /.modal-content --> 
      </div><!-- /.modal-dialog --> 
     </div><!-- /.modal --> 
    </div> 

와 당신이 로그를 클릭하면 버튼을 누르면 사용자 이름과 비밀번호를 제공하지 않고 페이지에서 Account/Login으로 리디렉션됩니다.

어떻게하면 인증 오류 팝업이 모달에 나타나고 계정 컨트롤러로 리디렉션되지 않습니까?

미리 도움을 청하십시오.

답변

1

먼저 확인 당신이 실제로 양식을 검증하기 위해 스크립트를 포함했다
1

클라이언트 측 유효성 검사에는보기 또는 레이아웃에 jquery 유효성 검사 번들이 포함됩니다.

@section scripts 
{ 
    @Scripts.Render("~/bundles/jqueryval") 
} 

또한, 당신은 당신의 등록 및 로그인 폼을 구현하는 대신 Html.BeginForm의 Ajax.BeginForm() 도우미를 사용할 수 있습니다.

<script src=".../Scripts/jquery.validate.js"></script> 
<script src=".../Scripts/jquery.validate.unobtrusive.js"></script> 
:
관련 문제