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>

当我运行应用程序时,LogOn 视图呈现正确,但单击提交按钮时没有任何反应。为什么?

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

请检查您是否在表单中添加了任何变为空的隐藏字段。简而言之,应该没有什么不需要为空并发布为空。

例如,我正在发布带有隐藏字段 ID(主要)的表单(用于创建),因此在创建实例中 Id 将为空,因此模型是有效的并且它看起来像任何未发布的东西。

于 2013-08-05T02:04:24.190 回答