asp.net MVC webgrid与分组

时间:2017-09-28 08:15:33

标签: c# .net asp.net-mvc-5 webgrid

有人可以帮助我通过webgrid跟踪视图

username    location    Date
a           abc         12/10/2017
a           def     ↑   12/10/2017
a           def         12/10/2017
a           def         12/11/2016
c           abc         12/10/2017





username    location    Date
a           abc         12/10/2017
a           def     ↓   12/10/2017
a           def         12/11/2016
c           abc         12/10/2017

我在对象列表中的用户名/位置和日期字段上创建了组。但无法进行上述观察

我正在尝试关注

 @{
        var grid = new WebGrid(Model, canPage: false, rowsPerPage: 5, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
        <div id="gridContent">
            @grid.GetHtml(tableStyle: "webGrid",
                headerStyle: "header",
                alternatingRowStyle: "alt",
                selectedRowStyle: "select",
                columns: grid.Columns(
                    grid.Column("Email", "User Name"),
                    grid.Column("location", "location"),
                    grid.Column("AccessedOn", "Date"),
                    grid.Column(format: (item) =>
                    {

                        if (item.count > 1)
                        {
                            WebGrid subGrid = new WebGrid(source: item.x);
                            return subGrid.GetHtml(tableStyle: "webGrid",
                                headerStyle: "header",
                                alternatingRowStyle: "alt",
                                selectedRowStyle: "select",
                                columns: grid.Columns(
                                    grid.Column("Email", null),
                                    grid.Column("location", null),
                                    grid.Column("AccessedOn", null))
                                );
                        }
                        else
                            return null;
                    }
                        )
                    ))



        </div>
    }

1 个答案:

答案 0 :(得分:0)

你试过这样的事吗

a=>a.GroupBy(a.username).groupBy(a.location).tolist()