Twitter bootstrap 在引导模式窗体.net core中显示详细信息
我正在尝试编辑属于索引视图id的记录 模式弹出窗口是打开的,但控制器中的id为空,所以它显示的是空白表单。 我在下面分享我的代码 _共享文件夹中的Model.cshtml视图Twitter bootstrap 在引导模式窗体.net core中显示详细信息,twitter-bootstrap,asp.net-core,Twitter Bootstrap,Asp.net Core,我正在尝试编辑属于索引视图id的记录 模式弹出窗口是打开的,但控制器中的id为空,所以它显示的是空白表单。 我在下面分享我的代码 _共享文件夹中的Model.cshtml视图 <div aria-hidden="true" aria-labelledby="modal-create-edit-user-label" role="dialog" tabindex="-1" id="modal-creat
<div aria-hidden="true" aria-labelledby="modal-create-edit-user-label" role="dialog" tabindex="-1" id="modal-create-edit-user" class="modal fade">
<div class="modal-dialog">
</div>
</div>
js代码
(function ($) {
function Index() {
var $this = this;
function initialize() {
$(".popup").on('click', function (e) {
modelPopup(this);
});
function modelPopup(reff) {
var url = $(reff).data('url');
$.get(url).done(function (data) {
debugger;
$('#modal-create-edit-user').find(".modal-dialog").html(data);
$('#modal-create-edit-user > .modal', data).modal("show");
});
}
}
$this.init = function () {
initialize();
};
}
$(function () {
var self = new Index();
self.init();
});
}(jQuery));
我认为问题在于您没有将
id
添加到中的请求中
$.get(url)
正如您在的文档中所看到的,您可以将数据作为第二个参数传入:
function modelPopup(reff) {
var url = $(reff).data('url');
var id = $(reff).data('id'); // Gets data from the "data-id" attribute
$.get(url, { id: id }).done(function (data) {
// ...
});
}
控制器操作现在应该获得您输入的数据id=“@item.id”
(function ($) {
function Index() {
var $this = this;
function initialize() {
$(".popup").on('click', function (e) {
modelPopup(this);
});
function modelPopup(reff) {
var url = $(reff).data('url');
$.get(url).done(function (data) {
debugger;
$('#modal-create-edit-user').find(".modal-dialog").html(data);
$('#modal-create-edit-user > .modal', data).modal("show");
});
}
}
$this.init = function () {
initialize();
};
}
$(function () {
var self = new Index();
self.init();
});
}(jQuery));
$.get(url)
function modelPopup(reff) {
var url = $(reff).data('url');
var id = $(reff).data('id'); // Gets data from the "data-id" attribute
$.get(url, { id: id }).done(function (data) {
// ...
});
}