如何使用Javascript将数据从所有WebGrid行传递到MVC控制器?

时间:2019-05-20 09:00:41

标签: javascript asp.net json model-view-controller webgrid

我正在尝试使用Javascript将数据从WebGrid(请参见下图)传递到Controller中。

enter image description here

当前,我只能遍历WebGrid并获取每一行的值。在下面的代码中,我得到了4个空警报(我认为我的WebGrid的行包括标题)。

到目前为止我所拥有的:

HTML

Selection.ShapeRange.Left = [B7].Left
Selection.ShapeRange.Top = [B7].Top

JavaScript

@{
                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",
                                htmlAttributes: new { id = "tableID" },
                                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>
                }
}

生成的WebGrid

enter image description here

希望有人可以帮助我,

提前谢谢!

0 个答案:

没有答案