2016-09-06 1 views
0

제출 단추가 컨트롤러의 게시 방법으로 이동하지 않습니다. 도움말 제발, 나는 ASP.Net에서 프로그래밍에 익숙하지 않은 이유와 제출 버튼이 컨트롤러의 게시 방법을 사용하지 않는 이유를 디버깅하려고합니다. 우리는 또한 웹 서비스 여기 제출 단추가 컨트롤러의 게시 방법으로 이동하지 않습니다.

를 사용하려고

는 계정의 코드 /보기/Login.cshtml

@using WebApplication3.Models 
@model LoginViewModel 
@{ 
    ViewBag.Title = "Log in"; 
} 

<h2>@ViewBag.Title.</h2> 
<div class="row"> 
    <div class="col-md-8"> 
     <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"> 
        @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" }) 
        <div class="col-md-10"> 
         @Html.TextBoxFor(m => m.Email, new { @class = "form-control" }) 
         @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" }) 
        </div> 
       </div> 
       <div class="form-group"> 
        @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" }) 
        <div class="col-md-10"> 
         @Html.PasswordFor(m => m.Password, new { @class = "form-control" }) 
         @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> 
       <div class="form-group"> 
        <div class="col-md-offset-2 col-md-10"> 
         <input type="submit" value="Log in" class="btn btn-default" /> 
        </div> 
       </div> 
       <p> 
        @Html.ActionLink("Register as a new user", "Register") 
       </p> 
       @* 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-4"> 
     <section id="socialLoginForm"> 
      @Html.Partial("_ExternalLoginsListPartial", new ExternalLoginListViewModel { ReturnUrl = ViewBag.ReturnUrl }) 
     </section> 
    </div> 
</div> 

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




Here is the partial code for the controller 
     // GET: /Account/Login 
     [AllowAnonymous] 
     public ActionResult Login() 
     { 
      return View(); 
     } 

     // 
     // POST: /Account/Login 
     [HttpPost] 
     [AllowAnonymous] 
     [ValidateAntiForgeryToken] 
     public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) 
     { 
      if (!ModelState.IsValid) 
      { 
       return View(model); 
      } 
      var RenewalClient = this.RenewalClient.ServiceClient; 
      bool isValidUser= RenewalClient.ValidateUser(model.Email,model.Password); 
      // This doesn't count login failures towards account lockout 
      // To enable password failures to trigger account lockout, change to shouldLockout: true 
      var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); 
      switch (result) 
      { 
       case SignInStatus.Success: 
        return RedirectToLocal(returnUrl); 
       case SignInStatus.LockedOut: 
        return View("Lockout"); 
       case SignInStatus.RequiresVerification: 
        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); 
       case SignInStatus.Failure: 
       default: 
        ModelState.AddModelError("", "Invalid login attempt."); 
        return View(model); 
      } 
     } 
+0

이 시도 : Html.BeginForm ("로그인", "계정", FormMethod.Post, 새로운 {에 enctype = "다중/폼 데이터"}) 나는이 시도 –

+0

, 같은 결과 –

답변

0

귀하의 HTML은 잘 될 것 같다. 익명 함수를 사용하여 BeginForm ("Login", "Account", FormMethod.Post, new {})의 마지막 인자로 정보를 전달하는 것이 좋습니다.

컨트롤러 메서드가 [HttpPost] 특성으로 장식되어 있는지 확인하십시오.이 특성이 동작 메서드에 없으면 GET 요청 만 제공하기 때문입니다.

+0

을 컨트롤러가 장식한다 [HttpPost] 특성. 코드가 문제가됩니다. –

관련 문제