动态 bootstrap 模态

Dynamic bootstrap modal

好吧,我想让我的 bootstrap 模态动态化,但不知道该怎么做。我知道我需要使用 @PredictioItems.Name 但不确定在哪里 :(

代码:

<div style="margin-top: 55px;" class="col-sm-10 col-sm-offset-1">
        @foreach (var PredictioItems in Model.Content.Children())
        {
            if (PredictioItems.GetPropertyValue("checkboxchecker").Equals(true))
            {
                <h4 style="color: #000;">@PredictioItems.GetPropertyValue("teamvsteam")</h4>
                <strong style="color: #000;">@PredictioItems.GetPropertyValue("predictinfo")</strong><br />
                <img src="@Umbraco.TypedMedia(PredictioItems.GetPropertyValue("matchimage")).Url" />
                <p style="color: #000">@Umbraco.Truncate(PredictioItems.GetPropertyValue("predictdescription").ToString(), 25)</p>
            <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">View full description & Livestream!</button>
                <hr />
            }

            <div id="myModal" class="modal fade" role="dialog">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">@PredictioItems.GetPropertyValue("teamvsteam")</h4>
                        </div>
                        <div class="modal-body">
                            <p>@PredictioItems.GetPropertyValue("predictdescription")</p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                    </div>

                </div>
            </div>
        }
    </div>

有人可以告诉我要更换什么才能使其正常工作吗?谢谢:)

应该这样做——正如@vel 所说,每个可能的模式 "instance" 都必须有一个唯一的 ID,打开它的按钮应该引用该 ID:

<div style="margin-top: 55px;" class="col-sm-10 col-sm-offset-1">
        @foreach (var PredictioItems in Model.Content.Children())
        {
            if (PredictioItems.GetPropertyValue("checkboxchecker").Equals(true))
            {
                <h4 style="color: #000;">@PredictioItems.GetPropertyValue("teamvsteam")</h4>
                <strong style="color: #000;">@PredictioItems.GetPropertyValue("predictinfo")</strong><br />
                <img src="@Umbraco.TypedMedia(PredictioItems.GetPropertyValue("matchimage")).Url" />
                <p style="color: #000">@Umbraco.Truncate(PredictioItems.GetPropertyValue("predictdescription").ToString(), 25)</p>
            <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal@(PredictioItems.Id)">View full description & Livestream!</button>
                <hr />
            }

            <div id="myModal@(PredictioItems.Id)" class="modal fade" role="dialog">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">@PredictioItems.GetPropertyValue("teamvsteam")</h4>
                        </div>
                        <div class="modal-body">
                            <p>@PredictioItems.GetPropertyValue("predictdescription")</p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                    </div>

                </div>
            </div>
        }
    </div>