我想用 MVC 中的动态数据填充模态弹出窗口内的下拉列表。当我单击 Open
时,DisplayModal
模式应在 dropdowmlist 中显示更新的数据。我的 Jquery
代码未显示下拉列表中包含新数据的模态弹出窗口。
查看
<table>
<tr>
<td>
@Html.DisplayName("IT")
</td>
<td>
<a class="LinkId" data-toggle="modal" data-url="/Home/_ModalPopup?Page=1">Open</a>
</td>
</tr>
<tr>
<td>
@Html.DisplayName("Sales")
</td>
<td>
<a class="LinkId" data-toggle="modal" data-url="/Home/_ModalPopup?Page=2">Open</a>
</td>
</tr>
</table>
@{Html.RenderAction("__MEmpModal"); }
部分模态
<div class="modal fade" id="DisplayModal" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
@Html.DropDownListFor(m => m.Category, Model.CategoriesList, new { @class = "form-control" })
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary pull-right">Save</button>
</div>
</div>
</div>
</div>
脚本
$(document).on("click", '.LinkId', function (e) {
debugger;
$.ajax({
url: $(this).data("url"),
type: "GET",
}).done(function (partialViewResult) {
$("#DisplayModal").html(partialViewResult);
$('#DisplayModal').focus();
});
});
最佳答案
试试这个。
链接
<a href="/Home/_ModalPopup?Page=1" class="modal-link"> Open</a>
脚本
$('body').on('click', '.modal-link', function (e) {
$('#modal-container').removeData('bs.modal');
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
var url = $(this).attr('href');
$.get(url, function (data) {
$('#modal-content').html(data);
$('#modal-container').modal('show');
});
});
关于jquery - 如何在 MVC 中使用动态数据填充模态弹出窗口内的下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604726/