1

下面的 Ajax.ActionLink 有一个空的 AjaxOptions。令人惊讶的是,它会自动将 ajax 响应呈现到模态中并替换整个 .modal-body 元素。我的意图是将响应呈现到#ItemCommentModalBody div 中。无论我如何设置 UpdateTargetId 和 InsertionMode,即使是空的 AjaxOptions,响应也将替换整个 .modal-body div。这是一个错误吗?模态由引导程序触发。

@Ajax.ActionLink("Add a comment", "AddComment", "Document", new { area = "", itemId = Model.ItemId }, new AjaxOptions {  }, new { @class = "btn btn-warning", data_toggle = "modal", data_target = "#ItemCommentModal" })
<div id="ItemCommentModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="lblItemCommentModal" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-body">
            <div id ="ItemCommentModalBody">

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

4

1 回答 1

1

它实际上似乎与 data_toggle = "modal" 属性有关。如果您将其从操作链接中删除,而是触发一个显示模式的 OnSuccess 事件,则一切正常。

@Ajax.ActionLink("Add a comment", "AddComment", "Document", 
    new { area = "", itemId = Model.ItemId },
    new AjaxOptions { UpdateTargetId = "ItemCommentModalBody", OnSuccess = "showModal" },
    new { @class = "btn btn-warning" })

并且 showModal 函数将简单地触发通常与 data_toggle 属性绑定的显示模式函数。

function showModal() {
    $('#ItemCommentModal').modal('show');
}
于 2016-09-01T18:41:30.123 回答