如何遍历WebGrid并获取DropDownList的选定值?

时间:2019-05-20 07:29:16

标签: c# asp.net view row webgrid

我试图弄清楚如何通过以下网络网格进行迭代:

enter image description here

我想要实现的是遍历此WebGrid并将彼此之间的每一行的“ A”列的值链接到“其他”列,例如此WebGrid:

“ key1”->“ otherkey2”,

“ key2”->“ otherkey3”,

“ key3”->“ otherkey3”

迭代完成后,我想将此数据(在dictionary<string, string>中优先)发送到我的控制器。

我的代码:

HTML

@{
                if (Model != null && Model.Count() > 0)
                {
                    var grid = new WebGrid(canPage: true, rowsPerPage: 10);
                    grid.Bind(source: Model, rowCount: 0, autoSortAndPage: false);

                    <div class="row" id="content2">
                        <div class="col-lg-12 d-flex align-items-stretch">

                            @grid.Table(tableStyle: "table table-responsive table-striped table-bordered",
                                columns: grid.Columns(
                                grid.Column(columnName: "A", header: "A", format:@<text><div class="" data-id="@item.KeyA" data-propertyname="KeyA">@item.KeyA</div></text>),
                                grid.Column("Other", header: "Other", format: @<text>@Html.DropDownList("OtherKey", (IEnumerable<SelectListItem>)ViewBag.OtherKeysList, new { @class = "extra-class" })</text>)))
                        </div>
                        <!--Pagerlist for webgrid-->
                        <div class="col-lg-12 d-flex align-items-stretch">
                            @grid.PagerList(mode: WebGridPagerModes.All, paginationStyle: "pagination pagination-small pagination-right")
                        </div>

                        @Html.Hidden("dir", grid.SortDirection)
                        @Html.Hidden("col", grid.SortColumn)
                    </div>
                }
}

JavaScript

<script type="text/javascript">
       $(document).ready(function () {
           $("#btnSubmit").click(function () {
               //Iterate here
           });
       });
</script>

0 个答案:

没有答案