jquery-dirtyforms无法使用ajax actionlink - UpdateTargetID

时间:2016-04-22 00:54:48

标签: jquery ajax forms actionlink jquery-dirtyforms

我在我网站的所有表单上配置了jquery.dirtyforms。当表单很脏时它工作正常,我试图关闭页面。但它并不适用于不引人注目的ajax调用。 (Ajax.ActionLink),调用正常进行。

有什么想法吗?

CODE:

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Create</title>

    <script src="~/Scripts/jquery-2.2.1.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    <script src="~/Scripts/jquery.dirtyforms.js"></script>

    <script type="text/javascript">
      $(document).ready(function(){
          $('form').dirtyForms();
      })
    </script>
</head>
<body>
    @using (Html.BeginForm()) 
    {
        @Html.AntiForgeryToken()
        <div id="update">
            <div class="form-horizontal">                
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Create" class="btn btn-default" />
                    </div>
                </div>
            </div>
        </div>
    }

    <div>
        @Html.ActionLink("Back to List", "Index")
        @Ajax.ActionLink("Back to List", "Index", new AjaxOptions {UpdateTargetId = "update"})
    </div>
</body>
</html>

当表单变脏时,Html.ActionLink会触发Stay / Leave弹出窗口,但是Ajax.ActionLink只会继续并在所需的div中加载Index View。 我想要实现的是在单击Ajax.ActionLink时触发脏块弹出。

0 个答案:

没有答案