0

我在我网站的所有表单上都配置了 jquery.dirtyforms。当表单很脏时它工作正常,例如我尝试关闭页面。但它根本不适用于不显眼的 ajax 调用。(Ajax.ActionLink),调用正常进行。

有任何想法吗?

代码:

<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 中加载索引视图。我想要实现的是在单击 Ajax.ActionLink 时也触发dirtyforms 弹出窗口。

4

0 回答 0