下面的Ajax.ActionLink有一个空的AjaxOptions。令人惊讶的是,它自动将ajax响应呈现为模态并替换整个.modal-body元素。我的目的是将响应呈现到#ItemCommentModalBody div中。无论我如何设置UpdateTargetId和InsertionMode,即使使用空的AjaxOptions,响应仍会替换整个.modal-body div。这是一个错误吗?模态由bootstrap触发。
@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>
答案 0 :(得分: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属性绑定的show modal函数。
function showModal() {
$('#ItemCommentModal').modal('show');
}