1

AccountControllerにLogOn部分ビューがあります:

    public ActionResult LogOn()
    {
        return PartialView();
    }

    //
    // POST: /Account/LogOn

    [HttpPost]
    public ActionResult LogOn(LogOnModel model, string returnUrl)
    {
        if (ModelState.IsValid)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                }
                else
                {
                    ModelState.AddModelError("", Resources.Account.Account.LoginFailureText);
                }
            }
        }

        return PartialView(model);
    }

、_Layout.cshtmlでこれを部​​分的にレンダリングします。

@{Html.RenderAction("LogOn", "Account");}

LogOn.cshtmlビューは次のとおりです。

@model Kalimat.Web.Models.LogOnModel

<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>

<div class="leftbanner login">
    <div class="bookicon">
        <img src="@Url.Content(@Kalimat.Web.Resources.Common.bookiconImgSrc)" alt="@Kalimat.Web.Resources.Common.bookiconImgAlt" />
    </div>
    <div class="strip">
        @MvcHtmlString.Create(Kalimat.Web.Resources.Account.Account.LoginTitle)
    </div>
    <div class="shade_2">
        <img src="@Url.Content(@Kalimat.Web.Resources.Common.shade_2ImgSrc)" alt="@Kalimat.Web.Resources.Common.shade_2ImgAlt" />
    </div>
    <div class="insidetext">
        @{
            //Logined user view
            if (Request.IsAuthenticated)
            {
                <div id="LoginView1">
                    @{<text>@Kalimat.Web.Resources.Account.Account.WelcomeText <strong>@Model.UserName</strong>!</text>}
                    <br />
                    <a id="LoginStatus1" href="">@Kalimat.Web.Resources.Account.Account.LoginStatusText</a>
                    <a id="ChangePassLinkButton" href="">@Kalimat.Web.Resources.Account.Account.ChangePswText</a>
                </div>
            }
            else
            {
                @Html.LabelFor(m => m.UserName)
                @Html.TextBoxFor(m => m.UserName, new { @class = "inputfield" })
                @Html.ValidationMessageFor(m => m.UserName, "*")
                <br />
                @Html.LabelFor(m => m.Password)
                @Html.PasswordFor(m => m.Password, new { @class = "inputfield" })
                @Html.ValidationMessageFor(m => m.Password, "*")
                <br />
                <span class="remove_shop">
                    @Html.CheckBoxFor(m => m.RememberMe)
                    @Html.LabelFor(m => m.RememberMe)
                </span>
                <p>
                    ***<input type="submit" class="submit_Cart" value="@Kalimat.Web.Resources.Account.Account.LoginButtonText" />***
                </p>
                @Html.ValidationSummary(false, Kalimat.Web.Resources.Account.Account.LoginFailureText)
                <a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.NewAccountText</a>
                <br />
                <a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.RecoverPswText</a>
            }
        }
    </div>
</div>

アプリケーションを実行すると、ログオンビューは正しくレンダリングされますが、送信ボタンをクリックしても何も起こりません。なぜ?

4

3 に答える 3

4

最初にこの行の複製を停止します

if (ModelState.IsValid) {}

意味がありません...

あなたのコードを見ると、送信ボタンとすべてがありますが、私はあなたが欠けていると思います

@using(Ajax.BeginForm())
{
     //put all your html element in this
     // and also put submit button in it ...
}

Ajax.BeginForm()のパラメーターは次のとおりです。

Ajax.BeginForm(
    string "ActionName",
    string "ControllerName",
    new routevalues {id="IDValue",message="MyMessage"},
    new AjaxOptions {OnBegin=[someFunction], OnFailure=[failureFunction] },
    new { id = "FormName" }
)

これは、ajaxを使用してアクションを投稿しているためです...

于 2011-08-04T12:20:32.200 に答える
0

フォームに送信したかどうかわかりませんか?

追加する必要があります:

@using(Html.BeginForm("Logon", "Account"))
{
    // Submit form bits here
}

情報を送信するためにログインビットの周り?

于 2011-08-04T12:01:50.330 に答える
-1

nullになるフォームに非表示フィールドを追加したかどうかを確認してください。簡単に言えば、nullとして投稿する必要がないものは何もないはずです。

たとえば、ID(プライマリ)の非表示フィールドを使用してフォーム(作成用)を投稿していたため、作成インスタンスではIDがnullになるため、モデルは有効であり、投稿されていないもののように見えます。

于 2013-08-05T02:04:24.190 に答える