Ajax.BeginForm中的OnSuccess功能未执行

时间:2017-04-08 08:31:54

标签: javascript jquery ajax asp.net-mvc twitter-bootstrap

我有以下表格在我的页面的Bootstrap模式中打开:

<div id="myModalLogin" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Sign in</h4>
            </div>
            <div class="modal-body" style="text-align: center;">
                @using (Ajax.BeginForm("Login", "Home", new AjaxOptions
                {
                    HttpMethod = "POST",
                    InsertionMode = InsertionMode.Replace,
                    UpdateTargetId = "target",
                    OnSuccess = "ajaxSuccess"
                }))
                {
                    <div class="sign_up_container">
                        Email:<br />
                        @Html.EditorFor(x => x.Login.Email, new { htmlAttributes = new { @class = "sign_up_container_input_style" } })<br/>
                        @Html.ValidationMessageFor(x => x.Login.Email, null, new { @class = "text-danger" })
                    </div>
                    <div class="sign_up_container">
                        Password:<br />
                        @Html.EditorFor(x => x.Login.Password, new { htmlAttributes = new { @class = "sign_up_container_input_style" } })
                        <br/><a href="#">Forgott password?</a>
                    </div>
                    <div class="sign_up_container">
                        <br />
                        <button type="submit" class="btn_style_3 btn">Login</button>
                    </div>
                }
            </div>
            <div class="modal-footer">

            </div>
        </div>
    </div>
</div>

下面我有我的JavaScript:

<script>

    function ajaxSuccess(result) {
        console.log("hello");
       console.log(result)
    }
</script>

这是我的控制器:

 public ActionResult Login(homeIndexViewModel model)
{
    return Json("hej");
}

我遇到的问题是ajaxSuccess永远不会被触发。当我检查控制台时,我可以看到发出一个POST并且响应包含值&#34; hej&#34;来自控制器。但是我的JavaScript函数没有被解雇。

我已包含以下JavaScript文件:

<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.bootstrap.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>

我也启用了:

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

制作一个ajax-post,但我的OnSuccess函数永远不会被触发。

0 个答案:

没有答案