我有一个带有2个选择的下拉菜单,当您选择其中任何一个时,都应该出现一个带有文件内容的模式,以便用户编辑和保存更改。
我使用了断点,并且我知道该过程可以正确地通过我的控制器,但是模态没有显示。
以下是“首页”的cshtml中的下拉菜单
<div class="dropdown" style="margin-left: 7px;">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Configuration
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item load-config" href="#" id="btn-config" data-id="config">Codecept</a>
<a class="dropdown-item load-config" href="#" id="btn-json-config" data-id="steps-file">Step File</a>
</div>
</div>
选择一个选项后,我将调用关注jQuery
$(".load-config").click(function () {
var repository = $("#repositories").val();
var connectionId = sessionStorage.getItem("connectionId");
var branch = $("#branches").val();
var file = $(this).data("id");
$.ajax({
type: "GET",
data: { connectionId: connectionId, repositoryName: repository, branch: branch, file: file},
url: '@Url.Action("GetCurrentConfiguration", "Home")',
success: function (data) {
codeMirrorEditor.setValue(data.content);
$("#modal-code-editor").modal('show');
$("#modal-title").html(data.title);
setTimeout(function () {
codeMirrorEditor.refresh();
}, 200);
},
error: function () {
console.log("Error: could not cancel running test...")
}
});
});
在下面,您将找到模态的cshtml
<div id="modal-code-editor" class="modal fade" role="dialog" data-backdrop="static">
<div class="modal-dialog modal-lg">
<div class="modal-content" style="height: 768px;">
<div class="modal-header">
<h5 class="modal-title" id="modal-title"></h5>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<script>
var t;
$('#btn-config,#btn-json-config').click(function () {
button = $(this).attr('id');
});
$("#btn-save-code").click(function (e) {
var connectionId = sessionStorage.getItem("connectionId");
var filename = $("#modal-title").html();
var contents = codeMirrorEditor.getValue();
var repository = $("#repositories").val();
var branch = $("#branches").val();
var file = button;
var token = $("#__AjaxAntiForgeryForm input").val();
var dataWithToken = {
__RequestVerificationToken: token,
filename: filename,
connectionId: connectionId,
fileContents: contents,
repositoryName: repository,
branch: branch,
file: file
};
$.ajax({
type: "POST",
data: dataWithToken,
url: '@Url.Action("SaveFileContents", "Home")',
success: function (data) {
$("#modal-code-editor").modal('hide');
$.growl.notice({ message: "File saved successfully" });
},
error: function () {
$.growl.error({ message: "Saving file failed" });
}
});
});
</script>