Bootstrap Modal opening once on dblclick using jquery/Ajax but will not open again after closing

huangapple go评论70阅读模式
英文:

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:

 Study Name
Count
Type
Comment
Start Date
End Date
@foreach (var item in Model)
{

 @item.Name
@item.SubjectCount
@item.StudyTypeID
@item.Comment
@item.StartUtc.ToString("yyyy-mm-dd")
@item.EndUtc.ToString("yyyy-mm-dd")

}

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)"> 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"> @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 () {
        $(&#39;#editStudyModal&#39;).on(&#39;hidden.bs.modal&#39;, function () {
            $(this).removeData(&#39;bs.modal&#39;);
            $(&#39;#editStudyModal .modal-body&#39;).html(&#39;&#39;);
        });

        function openEditStudyModal(id) {
            var id = $(this).attr(&#39;id&#39;);
            var url = &#39;@Url.Action(&quot;Details&quot;,&quot;Studies&quot;)&#39;;
            $.ajax({
                url: url,
                type: &#39;post&#39;,
                data: { &quot;id&quot;: id },
                success: function (data) {
                    $(&#39;#editStudyPopup&#39;).html(data);
                    $(&#39;#editStudyModal&#39;).modal(&quot;show&quot;);
                }
            });
        });
    });

<!-- 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.

huangapple
  • 本文由 发表于 2023年5月14日 02:34:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定