0

送信ボタンをクリックするとスタックします。送信ボタンをクリックしても、HttpPost アクションに戻りません。コードを共有しています。

コントローラー: public class AccountController : コントローラー {

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

        //
        // GET: /Account/LogOn
        public ActionResult UserLogin()
        {
            return View();
        }

        [HttpPost]
        public ActionResult UserLogin(LogOn model)
        {
            if (ModelState.IsValid)
            {
                return View("Compltete", model);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }


    }

意見:

@model SanjiviniAnalytics.Models.LogOn

<h2>User Login</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm("UserLogin", "Account", FormMethod.Post)) {

    <div>
        <fieldset>
            <legend>Sign In</legend>

            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>
            <p>
                <input type="submit" value="Log In" />
            </p>
        </fieldset>
    </div>

}

モデル:

public class LogOn
{
    [Required]
    [Display(Name="User Name")]
    public string UserName { get; set; }

    [Required]
    [Display(Name="Password")]
    [DataType(DataType.Password)]
    public string Password { get; set;}
}

誰かが私が間違っている場所を見つけるのを手伝ってもらえますか?

4

3 に答える 3

2

Take Controllerout of the form.. MVC では、コントローラー名のコントローラー部分を含める必要はありません。

@using (Html.BeginForm("UserLogin","Account"))

また、メソッドとして POST を指定してみてください。

@using (Html.BeginForm("UserLogin", "Account", FormMethod.Post))
于 2012-08-16T12:05:49.783 に答える
1

これを試して:

@using (Html.BeginForm("UserLogin","Account", FormMethod.Post))

(サイモンが私を打ち負かすのを見たところです:))

于 2012-08-16T12:17:17.503 に答える
0

サイモンが言ったように、以下は機能します。HttpPost アクションは FormMethod.Post メソッドから実行されます。

@using (Html.BeginForm("UserLogin", "Account", FormMethod.Post))
于 2012-08-16T13:01:18.273 に答える