Html/Css CSHTML - 某些项目的手风琴未打开

Html/Css CSHTML - Accordion not opening for SOME items

我的问题是我正在为页面创建评论部分。每个评论可以有多个回复。我正在使用 bootstrap 手风琴来实现此目的,并通过 C# MVC 代码动态创建手风琴。我不明白为什么有些手风琴可以正确打开而有些则不能。每个评论由评论、编辑按钮、删除按钮和回复按钮组成。 有时手风琴不会打开,但是当我去Chrome中的检查舱口时,我可以将"show"关键字放入我要扩展的div中,它就这样做了。 这是呈现的代码。我不认为问题出在 C# 代码上,因为手风琴有时会打开。是否存在我不知道的等级制度?顺便说一句,第一个 div 是最外面的手风琴,用于显示或隐藏所有评论。

<div class="container-fluid">
<div class="row">
    <div class="col-sm-11 col-md-11 col-lg-11">
        <h2 class="fl-left pt-40 text-white fbold">COMMENTS</h2>
    </div>
    <div class="col-sm-1 col-md-1 col-lg-1 pt-40">
        <a class="btn-accordion" href="#div-10" data-toggle="collapse" aria-expanded="true">
            <span class="btn-accordion-arrow comments-top"><img src="/Content/Images/up-chevron-blue.png" alt=""></span>
        </a>
    </div>
</div>
<div class="collapse show" id="div-10" style="">
    <br>
    <br>
    <div class="container-fluid-0d41c31f-8629-4f02-bf4c-64af8f830975" style="padding-left:0px">
        <div class="row">
            <div class="col-sm-11 col-md-11 col-lg-11">
                <span class="text-white fbold">Mike &nbsp;Cave &nbsp;&nbsp;•&nbsp;&nbsp;</span><span class="blue-slate-text">03-Oct-2018 14:41</span>
            </div>
            <div class="col-sm-1 col-md-1 col-lg-1">
                <a class="btn-accordion collapsed" href="#0d41c31f-8629-4f02-bf4c-64af8f830975" data-toggle="collapse" data-target="#0d41c31f-8629-4f02-bf4c-64af8f830975" aria-expanded="false">
                    <span class="btn-accordion-arrow"><img src="/Content/Images/up-chevron-blue.png" alt=""></span>
                </a>
            </div>
        </div>
        <div class="collapse" id="0d41c31f-8629-4f02-bf4c-64af8f830975">
            <div class="row">
                <div class="col-sm-12 col-md-12 col-lg-12">
                    <span id="span-0d41c31f-8629-4f02-bf4c-64af8f830975">  First Comment for Dispute 001 - PARENT</span>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col-sm-8 col-md-8 col-lg-8">
                    <a href="#editModal" role="button" data-toggle="modal" data-comment="First Comment for Dispute 001 - PARENT" data-comment2="0d41c31f-8629-4f02-bf4c-64af8f830975" data-comment3="00000000-0000-0000-0000-000000000000"><i class="fa fa-pencil-square-o"></i> Edit </a>&nbsp;&nbsp;
                    <a id="0d41c31f-8629-4f02-bf4c-64af8f830975" href="#" onclick="deleteComment('0d41c31f-8629-4f02-bf4c-64af8f830975');return false;"><i class="fa fa-trash"></i> Delete</a>&nbsp; &nbsp;
                </div>
                <div class="col-sm-3 col-md-3 col-lg-3">
                    <input type="checkbox" value="0d41c31f-8629-4f02-bf4c-64af8f830975" id="shareWCustomer-0d41c31f-8629-4f02-bf4c-64af8f830975" name="shareWCustomer-0d41c31f-8629-4f02-bf4c-64af8f830975" unchecked=""> Share With Customer
                </div>
                <div class="col-sm-1 col-md-1 col-lg-1">
                    <a href="#editModal2" role="button" data-toggle="modal" data-comment="First Comment for Dispute 001 - PARENT" data-comment2="0d41c31f-8629-4f02-bf4c-64af8f830975" data-comment3="00000000-0000-0000-0000-000000000000"><img src="/Content/Images/icon-replies.png" class="img-responsive icon-replies"></a>
                </div>
            </div>
            <hr class="hr-white">
            <br>
        </div>
    </div>
    <div class="container-fluid-0d41c31f-8629-4f02-bf4c-64af8f830975" style="padding-left:40px">
        <div class="row">
            <div class="col-sm-11 col-md-11 col-lg-11">
                <span class="text-white fbold">Mike &nbsp;Cave &nbsp;&nbsp;•&nbsp;&nbsp;</span><span class="blue-slate-text">03-Oct-2018 14:45</span>
            </div>
            <div class="col-sm-1 col-md-1 col-lg-1">
                <a class="btn-accordion collapsed" href="#612de2eb-f33c-4b30-b69c-825d0c8171bd" data-toggle="collapse" data-target="#612de2eb-f33c-4b30-b69c-825d0c8171bd" aria-expanded="false">
                    <span class="btn-accordion-arrow"><img src="/Content/Images/up-chevron-blue.png" alt=""></span>
                </a>
            </div>
        </div>
        <div class="collapse" id="612de2eb-f33c-4b30-b69c-825d0c8171bd">
            <div class="row">
                <div class="col-sm-12 col-md-12 col-lg-12">
                    <span id="span-612de2eb-f33c-4b30-b69c-825d0c8171bd">  Second Comment for Dispute 001 - First Child</span>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col-sm-8 col-md-8 col-lg-8">
                    <a href="#editModal" role="button" data-toggle="modal" data-comment="Second Comment for Dispute 001 - First Child" data-comment2="612de2eb-f33c-4b30-b69c-825d0c8171bd" data-comment3="0d41c31f-8629-4f02-bf4c-64af8f830975"><i class="fa fa-pencil-square-o"></i> Edit </a>&nbsp;&nbsp;
                    <a id="612de2eb-f33c-4b30-b69c-825d0c8171bd" href="#" onclick="deleteComment('612de2eb-f33c-4b30-b69c-825d0c8171bd');return false;"><i class="fa fa-trash"></i> Delete</a>&nbsp; &nbsp;
                </div>
                <div class="col-sm-3 col-md-3 col-lg-3">
                    <input type="checkbox" value="612de2eb-f33c-4b30-b69c-825d0c8171bd" id="shareWCustomer-612de2eb-f33c-4b30-b69c-825d0c8171bd" name="shareWCustomer-612de2eb-f33c-4b30-b69c-825d0c8171bd" unchecked=""> Share With Customer
                </div>
                <div class="col-sm-1 col-md-1 col-lg-1">
                    <a href="#editModal2" role="button" data-toggle="modal" data-comment="Second Comment for Dispute 001 - First Child" data-comment2="612de2eb-f33c-4b30-b69c-825d0c8171bd" data-comment3="0d41c31f-8629-4f02-bf4c-64af8f830975"><img src="/Content/Images/icon-replies.png" class="img-responsive icon-replies"></a>
                </div>
            </div>
            <hr class="hr-white">
            <br>
        </div>
    </div>
    <div class="container-fluid-0d41c31f-8629-4f02-bf4c-64af8f830975" style="padding-left:40px">
        <div class="row">
            <div class="col-sm-11 col-md-11 col-lg-11">
                <span class="text-white fbold">Mike &nbsp;Cave &nbsp;&nbsp;•&nbsp;&nbsp;</span><span class="blue-slate-text">03-Oct-2018 14:51</span>
            </div>
            <div class="col-sm-1 col-md-1 col-lg-1">
                <a class="btn-accordion" href="#a869e748-f0c3-461a-89bb-07bf29620d66" data-toggle="collapse" data-target="#a869e748-f0c3-461a-89bb-07bf29620d66" aria-expanded="true">
                    <span class="btn-accordion-arrow"><img src="/Content/Images/up-chevron-blue.png" alt=""></span>
                </a>
            </div>
        </div>
        <div class="collapse show" id="a869e748-f0c3-461a-89bb-07bf29620d66" style="">
            <div class="row">
                <div class="col-sm-12 col-md-12 col-lg-12">
                    <span id="span-a869e748-f0c3-461a-89bb-07bf29620d66">  First REPLY  for Dispute 001 - to comment 1</span>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col-sm-8 col-md-8 col-lg-8">
                    <a href="#editModal" role="button" data-toggle="modal" data-comment="First REPLY  for Dispute 001 - to comment 1" data-comment2="a869e748-f0c3-461a-89bb-07bf29620d66" data-comment3="0d41c31f-8629-4f02-bf4c-64af8f830975"><i class="fa fa-pencil-square-o"></i> Edit </a>&nbsp;&nbsp;
                    <a id="a869e748-f0c3-461a-89bb-07bf29620d66" href="#" onclick="deleteComment('a869e748-f0c3-461a-89bb-07bf29620d66');return false;" class="collapse show" style=""><i class="fa fa-trash"></i> Delete</a>&nbsp; &nbsp;
                </div>
                <div class="col-sm-3 col-md-3 col-lg-3">

                    <input type="checkbox" value="a869e748-f0c3-461a-89bb-07bf29620d66" id="shareWCustomer-a869e748-f0c3-461a-89bb-07bf29620d66" name="shareWCustomer-a869e748-f0c3-461a-89bb-07bf29620d66" unchecked=""> Share With Customer

                </div>
                <div class="col-sm-1 col-md-1 col-lg-1">
                    <a href="#editModal2" role="button" data-toggle="modal" data-comment="First REPLY  for Dispute 001 - to comment 1" data-comment2="a869e748-f0c3-461a-89bb-07bf29620d66" data-comment3="0d41c31f-8629-4f02-bf4c-64af8f830975"><img src="/Content/Images/icon-replies.png" class="img-responsive icon-replies"></a>
                </div>
            </div>
            <hr class="hr-white">
            <br>
        </div>
    </div>
    <div class="container-fluid-0d41c31f-8629-4f02-bf4c-64af8f830975" style="padding-left:40px">
        <div class="row">
            <div class="col-sm-11 col-md-11 col-lg-11">
                <span class="text-white fbold">Mike &nbsp;Cave &nbsp;&nbsp;•&nbsp;&nbsp;</span><span class="blue-slate-text">03-Oct-2018 15:12</span>
            </div>
            <div class="col-sm-1 col-md-1 col-lg-1">
                <a class="btn-accordion" href="#c768c95c-d926-41f7-a237-8b6803c9521d" data-toggle="collapse" data-target="#c768c95c-d926-41f7-a237-8b6803c9521d" aria-expanded="true">
                    <span class="btn-accordion-arrow"><img src="/Content/Images/up-chevron-blue.png" alt=""></span>
                </a>
            </div>
        </div>
        <div class="collapse show" id="c768c95c-d926-41f7-a237-8b6803c9521d" style="">
            <div class="row">
                <div class="col-sm-12 col-md-12 col-lg-12">
                    <span id="span-c768c95c-d926-41f7-a237-8b6803c9521d">  Second REPLY  for Dispute 001 - to comment  that was working</span>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col-sm-8 col-md-8 col-lg-8">
                    <a href="#editModal" role="button" data-toggle="modal" data-comment="Second REPLY  for Dispute 001 - to comment  that was working" data-comment2="c768c95c-d926-41f7-a237-8b6803c9521d" data-comment3="0d41c31f-8629-4f02-bf4c-64af8f830975"><i class="fa fa-pencil-square-o"></i> Edit </a>&nbsp;&nbsp;
                    <a id="c768c95c-d926-41f7-a237-8b6803c9521d" href="#" onclick="deleteComment('c768c95c-d926-41f7-a237-8b6803c9521d');return false;" class="collapse show" style=""><i class="fa fa-trash"></i> Delete</a>&nbsp; &nbsp;
                </div>
                <div class="col-sm-3 col-md-3 col-lg-3">

                    <input type="checkbox" value="c768c95c-d926-41f7-a237-8b6803c9521d" id="shareWCustomer-c768c95c-d926-41f7-a237-8b6803c9521d" name="shareWCustomer-c768c95c-d926-41f7-a237-8b6803c9521d" unchecked=""> Share With Customer

                </div>
                <div class="col-sm-1 col-md-1 col-lg-1">
                    <a href="#editModal2" role="button" data-toggle="modal" data-comment="Second REPLY  for Dispute 001 - to comment  that was working" data-comment2="c768c95c-d926-41f7-a237-8b6803c9521d" data-comment3="0d41c31f-8629-4f02-bf4c-64af8f830975"><img src="/Content/Images/icon-replies.png" class="img-responsive icon-replies"></a>
                </div>
            </div>
            <hr class="hr-white">
            <br>
        </div>
    </div>
</div>

*** 如您所见,呈现的代码看起来不错,这是 C# 视图 .cshtml:--

<div class="container-fluid">
<div class="row">
    <div class="col-sm-11 col-md-11 col-lg-11">
        <h2 class="fl-left pt-40 text-white fbold">COMMENTS</h2>
    </div>
    <div class="col-sm-1 col-md-1 col-lg-1 pt-40">
        <a class="btn-accordion collapsed" href="#div-10" data-toggle="collapse" aria-expanded="false">
            <span class="btn-accordion-arrow comments-top"><img src="~/Content/Images/up-chevron-blue.png" alt="" /></span>
        </a>
    </div>
</div>
<div class="collapse" id="div-10">
<br /><br />
@if (Model.DisputeComments != null)
{@*list of comment lists*@
    foreach (var list in Model.DisputeComments)
    { @*comment list*@
        foreach (var comment in list)
        {
            var indent = comment.ParentID != Guid.Empty ? "40px" : "0px";
            var containerName = comment.ParentID == Guid.Empty ? comment.Id : comment.ParentID; @*use for removing on delete*@

            <div class="container-fluid-@containerName" style="padding-left:@indent">
                <div class="row">
                    <div class="col-sm-11 col-md-11 col-lg-11">
                        <span class="text-white fbold">@comment.IbasUser.FirstName &nbsp;@comment.IbasUser.LastName &nbsp;&nbsp;&bull;&nbsp;&nbsp;</span><span class="blue-slate-text">@comment.EntryDate.ToString("dd-MMM-yyyy HH:mm")</span>
                    </div>
                    <div class="col-sm-1 col-md-1 col-lg-1">
                        <a class="btn-accordion collapsed" href="#@comment.Id" data-toggle="collapse" data-target="#@comment.Id" aria-expanded="false">
                            <span class="btn-accordion-arrow"><img src="~/Content/Images/up-chevron-blue.png" alt="" /></span>
                        </a>
                    </div>
                </div>
                <div class="collapse" id="@comment.Id">
                    <div class="row">
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <span id="span-@comment.Id">  @comment.Description</span>
                        </div>
                    </div>
                    <br />
                    <div class="row">
                        <div class="col-sm-8 col-md-8 col-lg-8">                                        
                            <a href="#editModal" role="button" data-toggle="modal" data-comment="@comment.Description" data-comment2="@comment.Id" data-comment3="@comment.ParentID"><i class="fa fa-pencil-square-o"></i> Edit </a>&nbsp;&nbsp;
                            <a id="@comment.Id" href="#" onclick="deleteComment('@comment.Id');return false;"><i class="fa fa-trash"></i> Delete</a>&nbsp; &nbsp;                                        
                        </div>
                        <div class="col-sm-3 col-md-3 col-lg-3">
                            @{
                                    var isChecked = "checked";     
                                    if (comment.ShareWithCustomer == false) { isChecked = "unchecked"; }
                            }
                            <input type="checkbox" value="@comment.Id" id="shareWCustomer-@comment.Id" name="shareWCustomer-@comment.Id" @isChecked>  Share With Customer

                        </div>
                        <div class="col-sm-1 col-md-1 col-lg-1">                                        
                            <a href="#editModal2" role="button" data-toggle="modal" data-comment="@comment.Description" data-comment2="@comment.Id" data-comment3="@comment.ParentID"><img src="~/Content/Images/icon-replies.png" class="img-responsive icon-replies" /></a>
                        </div>
                        </div>
                        <hr class="hr-white" />
                        <br />
                    </div>
            </div>
            } @* end of inner for each *@
        } @*end of outer for each*@
    }
</div>@*end of Comments accordian*@

@* 容器结束 *@

** 我尝试添加 CSS 但像往常一样 Stack overflow 说它未格式化,我会在我 post 这么多之后尝试添加它。感谢您的帮助!

我终于弄清了我的问题。 Collapsing divs 使用当前评论 GUId 作为标识符。我这样做是因为评论是即时呈现的,评论 ID 用于编辑和删除 div 中的评论。我去掉了除折叠 div 和按钮之外的所有内容,但它仍然没有用。这是我用 GUID 代替计数器作为崩溃的标识符 div。这成功了,手风琴正常工作。我不知道为什么 GUID 作为 ID 会使 Accordion 变得混乱,尤其是当我在将列表动态呈现为 html 时经常使用 GUID 作为 id。无论如何,我认为这是一场胜利。感谢 Pete 的观看。