如何在选中时从Html.grid获取行

时间:2014-07-30 14:27:05

标签: c# jquery html asp.net-mvc

我有一个像这样的网格:

<div class="div_100">
    @Html.Grid(Model).Named("grid").Columns(columns =>
        {
            columns.Add()
                                .Encoded(false)
                                .Sanitized(false)
                                .SetWidth(30)
                                .Titled("Verzenden")
                                .RenderValueAs(n => Html.CheckBox("Verzonden", !n.Verzonden));
            columns.Add(n => n.StartDatum).Titled("Start datum").Sortable(true).SetWidth(100);
            columns.Add(n => n.EindDatum).Titled("Eind datum").Sortable(true).SetWidth(100);
            columns.Add(n => n.Impact).Titled("Impact").Sortable(true).SetWidth(100);
            columns.Add(n => n.NotificatieType.Type).Titled("Type").Sortable(true).SetWidth(100);
            columns.Add(n => n.Omschrijving).Titled("Omschrijving").Sortable(true).SetWidth(100);
            columns.Add(n => n.Diensten).Titled("Diensten").Sortable(true).SetWidth(100);
            columns.Add(n => n.ID).Titled("ID").Sortable(true).SetWidth(100);
        }).Filterable().SetLanguage("nl")
</div>

经过一番努力,我已经能够添加复选框了。 现在当我创建复选框时,我默认检查它们!n.Verzonden =总是错误

我默认检查它们是真的,因为它不太可能被取消选中(10次中有9次需要检查,这样可以节省用户一些时间)

现在,当用户在此页面上完成并按下按钮时,我想要从所选行中获取所有columns.Add(n => n.ID).Titled("ID") ID。

那么如何获取所选行的所有ID?

我目前正在使用$.post与我的控制器进行通信,但也许有更好的方式,例如只是发送模型,我曾经用提交按钮填充网格或其他东西(对整个mvc事情并不擅长)

修改

渲染的html:

<div class="div_100">
<div class="grid-mvc" data-lang="nl" data-gridname="grid" data-selectable="true" data-multiplefilters="false">
    <div class="grid-wrap">
        <table class="table table-striped grid-table">
            <thead>
                <tr>
                    <th class="grid-header" style="width:30px;">
                        <div class="grid-header-title">
                            <span>Verzenden</span>
                        </div>
                    </th>
                    <th class="grid-header" style="width:100px;">
                        <div class="grid-filter" data-filterdata="[]" data-name="StartDatum" data-type="System.DateTime" data-widgetdata="null">
                            <span class="grid-filter-btn" title="Filter this column"></span>
                        </div>
                        <div class="grid-header-title">
                            <a href="?grid-column=StartDatum&amp;grid-dir=0">Start datum</a>
                        </div>
                    </th>
                    <th class="grid-header" style="width:100px;">
                        <div class="grid-filter" data-filterdata="[]" data-name="EindDatum" data-type="System.DateTime" data-widgetdata="null">
                            <span class="grid-filter-btn" title="Filter this column"></span>
                        </div>
                        <div class="grid-header-title"><a href="?grid-column=EindDatum&amp;grid-dir=0">Eind datum</a></div>
                    </th>
                    <th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="Impact" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=Impact&amp;grid-dir=0">Impact</a></div></th>
                    <th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="NotificatieType.Type" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=NotificatieType.Type&amp;grid-dir=0">Type</a></div></th>
                    <th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="Omschrijving" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=Omschrijving&amp;grid-dir=0">Omschrijving</a></div></th>
                    <th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="Diensten" data-type="System.String" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=Diensten&amp;grid-dir=0">Diensten</a></div></th>
                    <th class="grid-header" style="width:100px;"><div class="grid-filter" data-filterdata="[]" data-name="ID" data-type="System.Guid" data-widgetdata="null"><span class="grid-filter-btn" title="Filter this column"></span></div><div class="grid-header-title"><a href="?grid-column=ID&amp;grid-dir=0">ID</a></div></th>
                </tr>

            </thead>
            <tbody>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name="">
                        <input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" />
                    </td>
                    <td class="grid-cell" data-name="StartDatum">25-7-2014 10:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">25-7-2014 11:00:00</td>
                    <td class="grid-cell" data-name="Impact">Volledige onderbreking</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Test</td>
                    <td class="grid-cell" data-name="Diensten">Volledige dienstverlening</td>
                    <td class="grid-cell" data-name="ID">3a2a53b9-d92a-4504-874d-5a901ad01041</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">25-7-2014 12:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">25-7-2014 13:00:00</td>
                    <td class="grid-cell" data-name="Impact">Volledige onderbreking</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Test</td>
                    <td class="grid-cell" data-name="Diensten">Volledige dienstverlening</td>
                    <td class="grid-cell" data-name="ID">4c499f6c-53c8-49e0-b529-8b045819be10</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">25-7-2014 13:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">25-7-2014 15:00:00</td>
                    <td class="grid-cell" data-name="Impact">Volledige onderbreking</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving"></td>
                    <td class="grid-cell" data-name="Diensten">Volledige dienstverlening</td>
                    <td class="grid-cell" data-name="ID">977885c5-4c12-431b-ab72-59383b1824c6</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">28-7-2014 10:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">28-7-2014 11:00:00</td>
                    <td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Update print servers</td>
                    <td class="grid-cell" data-name="Diensten">Gedeeltelijke service</td>
                    <td class="grid-cell" data-name="ID">af4ed8cb-d033-47a4-96ae-f379bb484532</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">30-7-2014 10:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">30-7-2014 14:00:00</td>
                    <td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Niets</td>
                    <td class="grid-cell" data-name="Diensten">Volledige service</td>
                    <td class="grid-cell" data-name="ID">f2388fba-27ab-417a-ab39-a221d9d82fd3</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">30-7-2014 10:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">30-7-2014 14:00:00</td>
                    <td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Niets</td>
                    <td class="grid-cell" data-name="Diensten">Volledige service</td>
                    <td class="grid-cell" data-name="ID">3232fc33-0f82-4f76-a323-7ee988c4069a</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">30-7-2014 10:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">30-7-2014 14:00:00</td>
                    <td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Niets</td>
                    <td class="grid-cell" data-name="Diensten">Volledige service</td>
                    <td class="grid-cell" data-name="ID">b9c2ff88-f469-49f0-a23c-86ddb8bf7808</td>
                </tr>
                <tr class="grid-row ">
                    <td class="grid-cell" data-name=""><input checked="checked" id="Verzonden" name="Verzonden" type="checkbox" value="true" /><input name="Verzonden" type="hidden" value="false" /></td>
                    <td class="grid-cell" data-name="StartDatum">31-7-2014 11:00:00</td>
                    <td class="grid-cell" data-name="EindDatum">31-7-2014 14:00:00</td>
                    <td class="grid-cell" data-name="Impact">Gedeeltelijke onderbreking van de dienstverlening</td>
                    <td class="grid-cell" data-name="NotificatieType.Type">onderhoud</td>
                    <td class="grid-cell" data-name="Omschrijving">Niets</td>
                    <td class="grid-cell" data-name="Diensten">Volledige service</td>
                    <td class="grid-cell" data-name="ID">ecaa15da-0b91-4410-97ad-ba58148ebe4f</td>
                </tr>

            </tbody>
        </table>

    </div>
</div>

1 个答案:

答案 0 :(得分:1)

尝试

$('input:checked').each(function () {
  var row = $(this).closest('tr');
  var ID = row.children('td').eq(7).text();
  alert(ID); // for testing - don't know what you want to do with the ID's
});