2016-09-06 6 views
0

でPOSTメソッドに行きません。助けてください、私はASP.Netでプログラミングするのが初めてで、なぜサブミットボタンがコントローラのポストメソッドに行かないのかをデバッグしようとしています。送信ボタンは、ボタンをコントローラでPOSTメソッドに行かない提出contoller

また、ここでは、Webサービスに

を使用しようとしているあなたのHTMLは大丈夫のようですアカウント/ビュー/ 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

ためのコードです。 BeginForm( "Login"、 "Account"、FormMethod.Post、new {})の最後の引数として、匿名関数を使って情報を渡すことは常に良いことです。

この属性はアクションメソッドに存在しない場合、それが唯一のGETリクエストを提供しますので、あなたのコントローラのアクションは、[HttpPost]属性で装飾されているかどうかを確認します。

+0

ザ・コントローラが飾られています[HttpPost]属性。コードが問題になっています。 –

関連する問題