0

我正在尝试在网格内创建一个网格。在嵌套父网格之前它很好,但是当我尝试嵌套另一个网格时,它显示WebGrid.Colums有一些无效的参数。我有以下代码

   <div id="lgrid" class="tablesorter">

  @{
     var grid = new WebGrid(Model.AssetDetails, rowsPerPage: 20, canSort: false, canPage: false, ajaxUpdateContainerId: "1grid");
    }
       @grid.GetHtml(
    tableStyle: "lgrid",
    headerStyle: "head",
    alternatingRowStyle: "alt",
    columns: grid.Columns(
    grid.Column("S.N.", format: @<text>@{count++;}@count</text>, style: "sn"),
    grid.Column("Name", format: @<text>@item.Category.CategoryTitle</text>, style: "ItemNo"),  
    grid.Column("ItemDesc", format: @<text>@item.ItemDescription</text>, style: "ItemNo"),
    grid.Column("Quantity", format: @<text>@item.Quantity</text>, style: "Quantity"),
    grid.Column("Unit", format: @<text>@item.Unit.UnitSymbol</text>, style: "Unit"),
    grid.Column("Unit Price", format: @<text>@item.UnitPriceUSD</text>, style: "UnitPrice"),
    grid.Column("ExchangeRate", format: @<text>@item.ExchangeRate</text>, style: "ExchangeRate"),
    grid.Column("NPR", format: @<text>@{NPR = (@item.UnitPriceUSD * @item.ExchangeRate);}@NPR</text>, style: "NPR"),

    grid.Column("AssetDetails", format: (item) =>
    {
        WebGrid resGrid = new WebGrid(item.AssetDetails);
        return resGrid.GetHtml(
        columns: resGrid.Columns(
        resGrid.Column("Parameters", format: (resource) =>
            {
                WebGrid resParamGrid = new WebGrid(resource.AssetDetails);
                return resParamGrid.GetHtml(
                    columns: resParamGrid.Columns(
                        resParamGrid.Column("AssetNo", format: @<text>@newasst.AssetNo</text>),
                        resParamGrid.Column("SerialNo", format: @<text>@newasst.SerialNo</text>),
                        resParamGrid.Column("ModelNo", format: @<text>@newasst.ModelNo</text>),
                        resParamGrid.Column("Remarks", format: @<text>@newasst.Remarks</text>)
                    ),
                    displayHeader: false
                );
            })
        ),
        displayHeader: false
    );
    }),

    ))
4

1 回答 1

1

尝试格式化您的代码,您有一些混淆的左括号和右括号。你也有一些命名冲突和太多的网格。

试试这样:

@{
    var grid = new WebGrid(
        Model, 
        rowsPerPage: 20, 
        canSort: false, 
        canPage: false, 
        ajaxUpdateContainerId: "1grid"
    );
}

@grid.GetHtml(
    tableStyle: "lgrid",
    headerStyle: "head",
    alternatingRowStyle: "alt",
    columns: grid.Columns(
        grid.Column("S.N.", format: @<text>@{count++;}@count</text>, style: "sn"),
        grid.Column("Name", format: @<text>@item.CategoryTitle</text>, style: "ItemNo"),  
        grid.Column("ItemDesc", format: @<text>@item.ItemDescription</text>, style: "ItemNo"),
        grid.Column("Quantity", format: @<text>@item.Quantity</text>, style: "Quantity"),
        grid.Column("Unit", format: @<text>@item.UnitSymbol</text>, style: "Unit"),
        grid.Column("Unit Price", format: @<text>@item.UnitPriceUSD</text>, style: "UnitPrice"),
        grid.Column("ExchangeRate", format: @<text>@item.ExchangeRate</text>, style: "ExchangeRate"),
        grid.Column("NPR", format: @<text>@string.Format("{0:c}", item.UnitPriceUSD * item.ExchangeRate)</text>, style: "NPR"),
        grid.Column("AssetDetails", format: row =>
        {
            WebGrid resGrid = new WebGrid(row.AssetDetails);
            return resGrid.GetHtml(
                columns: resGrid.Columns(
                    resGrid.Column("AssetNo", format: @<text>@item.AssetNo</text>),
                    resGrid.Column("SerialNo", format: @<text>@item.SerialNo</text>),
                    resGrid.Column("ModelNo", format: @<text>@item.ModelNo</text>),
                    resGrid.Column("Remarks", format: @<text>@item.Remarks</text>)
                ),
                displayHeader: false
            );
        })
    )
)
于 2013-03-15T06:57:59.663 回答