登录时的Ajax加载程序(ASP.NET MVC)

本文关键字:ASP NET MVC 程序 Ajax 加载 登录 | 更新日期: 2023-09-27 17:57:52

我过去曾成功地使用过ajax-loader.gif,但它是针对用户的过滤。

我现在正试图在登录表单上使用它,但它不起作用(加载器没有显示)

这是我的代码:

@model Models.Login
@using (Ajax.BeginForm("Index", "Login", new AjaxOptions { UpdateTargetId = "ajaxUpdatedPanel", LoadingElementId = "loader" }))
{
<div id="box_login">
    <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>
    <br />
    <div class="mask roundedCorners" style="float:left;">
        <input type="submit" class="btn" value="Logg inn" />
    </div>
    <div id="loader" style="display:none;float:left;width:100px;margin: 8px 0 0 10px;">
        <img src="~/Content/images/loader16.gif" />
    </div>
</div>
@Html.ValidationSummary(true)
}

登录时的Ajax加载程序(ASP.NET MVC)

这应该做

$(document).ready(function() {
    $('form').submit(function() {
        if (!someValidations()) {
            return false;
        } else {
            $('form #loader').show();
        }
        return true;
    });
    function someValidations() {
        return true;
    }
});