Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 webgrid=如何动态构建_Asp.net Mvc 3_Webgrid - Fatal编程技术网

Asp.net mvc 3 webgrid=如何动态构建

Asp.net mvc 3 webgrid=如何动态构建,asp.net-mvc-3,webgrid,Asp.net Mvc 3,Webgrid,如何在对象列表中循环并在网格中的列中显示每个对象? 例如,我想做如下事情: @grid.GetHtml( tablestyle:="gridStyle", headerStyle:="headstyle", alternatingRowStyle:="alt", columns:=Grid.Columns( grid.column("column1", header:="Column1"), // This is where I

如何在对象列表中循环并在网格中的列中显示每个对象? 例如,我想做如下事情:

@grid.GetHtml(
    tablestyle:="gridStyle",
    headerStyle:="headstyle",
    alternatingRowStyle:="alt",
    columns:=Grid.Columns(
        grid.column("column1", header:="Column1"),

        // This is where I want to do something like:

        for each entry in ListOfObjects
            grid.column(entry.ItemA, header:="ItemA")
        next

我不认为这是你真正想要的,但这是你要求的:

@{
    List<WebGridColumn> cols = new List<WebGridColumn>();
    cols.Add(grid.Column("column1", header: "Column1"));
    foreach(var entry in ListOfObjects)
    {
        cols.Add(grid.Column(entry.ItemA, header: "ItemA"));
    }
}

@grid.GetHtml(
    tablestyle: "gridStyle",
    headerStyle: "headstyle",
    alternatingRowStyle: "alt-alt",
    columns: cols
)
@{
List cols=新列表();
列添加(网格列(“列1”,标题:“列1”);
foreach(ListOfObjects中的var条目)
{
cols.Add(grid.Column(entry.ItemA,标题:“ItemA”);
}
}
@grid.GetHtml(
表样式:“gridStyle”,
头型:“头型”,
alternatingRowStyle:“alt-alt”,
列:cols
)

您确定这是您真正想要做的吗?如果ListOfObjects有100个项,那么表中将有101列。