将 foreach 中的 id 传递给模态

pass id in foreach to modal

我正在尝试将@item.PhanHoi.ID传递给模态,但它@item.PhanHoi.ID只在第一个循环数处停止,有没有办法将id传递给模态?谢谢

                            <tbody>
                                    @foreach (var item in ViewBag.DsPhanHoi)
                                    {
                                    <tr class="sacss">
                                        <td></td>
                                        <td>@item.PhanHoi.Ten</td>
                                        <td>@item.PhanHoi.NoiDung</td>
                                        <td>@item.PhanHoi.TGphanhoi</td>
                                        <td>@item.PhanHoi.SDT</td>
                                        <td>@item.PhanHoi.Email</td>
                                        <td>@item.PhanHoi.DiaChi</td>
                                        <td class="datatable-ct">
                                            <div class="button-ap-list responsive-btn">
                                                <div class="btn-group btn-custom-groups" style="margin-left:26%">
                                                    <a class="btn btn-primary" href="@Url.Action("XemPH", new { id = item.PhanHoi.ID })"><i style="font-size:15px" class="fa fa-info-circle" aria-hidden="true"></i></a>
                                                    <a class="btn btn-danger" data-toggle="modal" data-target="#DangerModalalert" data-item="@item.PhanHoi.ID"><i style="font-size:15px" class="fa fa-trash" aria-hidden="true"></i></a>
                                                    <div id="DangerModalalert" class="modal modal-edu-general FullColor-popup-DangerModal fade" role="dialog">
                                                        <div class="modal-dialog">
                                                            <div class="modal-content">
                                                                <div class="modal-close-area modal-close-df">
                                                                    <a class="close" data-dismiss="modal" href="#"><i class="fa fa-close"></i></a>
                                                                </div>
                                                                <div class="modal-body">
                                                                    <span class="educate-icon educate-danger modal-check-pro information-icon-pro"></span>
                                                                    <h2>Cẩn thận!</h2>
                                                                    <p>Việc này sẽ xóa phản hồi này vĩnh viễn!!!</p>
                                                                </div>
                                                                <div class="modal-footer danger-md">
                                                                    <a data-dismiss="modal" href="#">Hủy bỏ</a>
                                                                    <a style="background-color:red" href="@Url.Action("XacNhanXoaPH", new {id =  @item.PhanHoi.ID })">Xóa!!</a>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                        </td>
                                    </tr>
                                        
                                    }
                                </tbody>
                       

modal的id不是唯一的,你可以尽量做到唯一,这样就不会一直调用第一个了modal.You可以用下面的代码:

                    <tbody>
                            @{ var count = 0;}   
                            @foreach (var item in ViewBag.DsPhanHoi)
                            {
                            <tr class="sacss">
                                <td></td>
                                <td>@item.PhanHoi.Ten</td>
                                <td>@item.PhanHoi.NoiDung</td>
                                <td>@item.PhanHoi.TGphanhoi</td>
                                <td>@item.PhanHoi.SDT</td>
                                <td>@item.PhanHoi.Email</td>
                                <td>@item.PhanHoi.DiaChi</td>
                                <td class="datatable-ct">
                                    <div class="button-ap-list responsive-btn">
                                        <div class="btn-group btn-custom-groups" style="margin-left:26%">
                                            <a class="btn btn-primary" href="@Url.Action("XemPH", new { id = item.PhanHoi.ID })"><i style="font-size:15px" class="fa fa-info-circle" aria-hidden="true"></i></a>
                                            <a class="btn btn-danger" data-toggle="modal" data-target="#DangerModalalert_@count" data-item="@item.PhanHoi.ID"><i style="font-size:15px" class="fa fa-trash" aria-hidden="true"></i></a>
                                            <div id="DangerModalalert_@count" class="modal modal-edu-general FullColor-popup-DangerModal fade" role="dialog">
                                                <div class="modal-dialog">
                                                    <div class="modal-content">
                                                        <div class="modal-close-area modal-close-df">
                                                            <a class="close" data-dismiss="modal" href="#"><i class="fa fa-close"></i></a>
                                                        </div>
                                                        <div class="modal-body">
                                                            <span class="educate-icon educate-danger modal-check-pro information-icon-pro"></span>
                                                            <h2>Cẩn thận!</h2>
                                                            <p>Việc này sẽ xóa phản hồi này vĩnh viễn!!!</p>
                                                        </div>
                                                        <div class="modal-footer danger-md">
                                                            <a data-dismiss="modal" href="#">Hủy bỏ</a>
                                                            <a style="background-color:red" href="@Url.Action("XacNhanXoaPH", new {id =  @item.PhanHoi.ID })">Xóa!!</a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </td>
                            </tr>
                            count++;    
                            }
                        </tbody>