英文:
Bootstrap Modal opening once on dblclick using jquery/Ajax but will not open again after closing
问题
I have a bootstrap grid in a partial view which is being rendered in my main view: Here is the code:
{
}
I have an edit modal which should open (and does the first time but only the first time) when I double click on a row. The JQuery/AJAX code is as follows:
$(document).ready(function () {
$('#editStudyModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
$('#editStudyModal .modal-body').html('');
});
function openEditStudyModal(id) {
var id = $(this).attr('id');
var url = '@Url.Action("Details","Studies")';
$.ajax({
url: url,
type: 'post',
data: { "id": id },
success: function (data) {
$('#editStudyPopup').html(data);
$('#editStudyModal').modal("show");
}
});
}
});
英文:
I have a bootstrap grid in a partial view which is being rendered in my main view: Here is the code:
<div class="study-container">
<div class="row no-gutters study-grid-header">
<div class="col-3 header-icon-hover header-icon-ws" id="col0" onclick="sortTable(0)">&nbsp;Study Name</div>
<div class="col-1 header-icon-hover d-flex justify-content-center" id="col1" onclick="sortTable(1)">Count</div>
<div class="col-1" id="col2" onclick="sortTable(0)">Type</div>
<div class="col-3 d-flex justify-content-left" id="col3" onclick="sortTable(1)" style="font-weight:normal">Comment</div>
<div class="col-2 d-flex justify-content-center" id="col4" onclick="sortTable(0)">Start Date</div>
<div class="col-2 d-flex justify-content-center" id="col5" onclick="sortTable(0)">End Date</div>
</div>
<div class="rows-container">
@foreach (var item in Model)
{
<div class="row study-grid-row jsTableRow" id="@item.Id" ondblclick="openEditStudyModal(@item.Id)">
<div class="col-3">&nbsp;@item.Name</div>
<div class="col-1 d-flex justify-content-center">@item.SubjectCount</div>
<div class="col-1">@item.StudyTypeID</div>
<div class="col-3">@item.Comment</div>
<div class="col-2 d-flex justify-content-center">@item.StartUtc.ToString("yyyy-mm-dd")</div>
<div class="col-2 d-flex justify-content-center">@item.EndUtc.ToString("yyyy-mm-dd")</div>
</div>
}
</div>
</div>
I have an edit modal which should open (and does the first time but only the first time) when I double click on a row. The JQuery/AJAX code is as follows:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
$(document).ready(function () {
$('#editStudyModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
$('#editStudyModal .modal-body').html('');
});
function openEditStudyModal(id) {
var id = $(this).attr('id');
var url = '@Url.Action("Details","Studies")';
$.ajax({
url: url,
type: 'post',
data: { "id": id },
success: function (data) {
$('#editStudyPopup').html(data);
$('#editStudyModal').modal("show");
}
});
});
});
<!-- end snippet -->
The Modal opens once but the only way I can get it to open again after it is closed is to reload the page. Has anyone got any clues as to what the problem might be?
答案1
得分: 0
问题似乎与表格是一个部分视图有关,所以我将HTML代码移到主视图中,问题得到解决。
英文:
The issue seemed to be related to the table being a partial view so I moved the html into the main view and that solved the problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论