【发布时间】:2017-11-28 16:36:06
【问题描述】:
我希望根据从我的 HTML 表中选择的行和从我的模型中获得的数据打开并填充一个 Bootstrap 模式,我的 HTML 表中有一个按钮,它将调用一个 JS 函数并传递识别它。我能够取回数据,但我只是不知道如何使用 JSON 列表填充模型。
这是我想要动态构建的模态:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Change User Deparment</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="Employee Number" class="form-control-label">Employee Number:</label>
<input type="text" class="form-control" id="Employee Number">
</div>
<div class="form-group">
<label for="userName" class="form-control-label">User Name:</label>
<input type="text" class="form-control" id="userName">
</div>
<label for="department">Select Department</label>
<select class="form-control" id="department">
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
</select>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Send message</button>
</div>
</div>
</div>
</div>
这个 My JS 函数,用于从我的模型中获取我的数据。
function editUser(id) {
//alert(userId);
$.ajax({
type: "GET",
url: '@Url.Action("GetUserDetails", "Admin")',
contentType: "application/json; charset=utf-8",
datatype: JSON,
data: ({ 'Value': id }),
success: function () {
},
error: function () {
alert(test);
}
});
}
【问题讨论】:
-
把你拿回来的数据也贴出来。我们需要知道您的数据格式。
标签: javascript html json ajax bootstrap-modal