Jquery 在MVC中打开模式弹出窗口时,如何从列表中获取模式中的Id

Jquery 在MVC中打开模式弹出窗口时,如何从列表中获取模式中的Id,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我有一张有记录列表的桌子。当我点击删除链接时,我想打开带有相关记录名的模式弹出窗口 当前,它总是从模式中的列表中获取第一个记录值 <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.HorseName) </th> <th> @Html.Dis

我有一张有记录列表的桌子。当我点击删除链接时,我想打开带有相关记录名的模式弹出窗口

当前,它总是从模式中的列表中获取第一个记录值

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.HorseName)
        </th>

        <th>
            @Html.DisplayName("Action")
        </th>
    </tr>

    @foreach (var item in Model)
    {
    <tr>
        <td class="name">
            @item.HorseName
        </td>

        <td>
            <a data-target="#HorseTrackerModal" data-toggle="modal" style="cursor:pointer">Delete</a>
            <div class="modal fade" id="HorseTrackerModal" role="dialog">
                <div id="dialogbox" class="modal-dialog" role="document">
                    <div class="modal-content">

                        <div class="modal-body">
                            Are you sure you want to delete @item.HorseName?
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" id="reset" data-dismiss="modal">No</button>

                            <a href="#" class="delete" data-id="@item.TrackerId" style="cursor:pointer"><button type="button" class="btn btn-secondary">Yes</button></a>
                        </div>
                    </div>
                </div>
            </div>
        </td>
    </tr>
    }
</table>

您当前的代码正在为集合中的每个项目呈现模式对话框所需的HTML标记!这意味着浏览器必须解析和呈现HTML,而这些HTML甚至可能不会显示给用户始终尝试呈现最小的HTML(更少的DOM节点数),以更进一步提供快速的web体验重复
id
属性是无效的HTML(在您的情况下,
以及为什么要在每次迭代中创建一个模式。您应该只有一个模式。@StephenMuecke,很抱歉怎么做。请指导我。显然有一些脚本与此相关-它们需要包含在您的迭代中。)question@StephenMuecke,我现在将添加那些有问题的脚本。
var url = '@Url.Action("Delete", "HorseTracker")';
$(document).on('click','.delete',function(){
    debugger;
    var id = $(this).data('id');
    var row = $(this).closest('tr');
    $.post(url, { id: id }, function(response) {
        if (response) {
            row.remove();
        }
    }).fail(function (response) {
        alert("Can not delete record!");
    });
});