2013-03-15 101 views
0

我想在網格內創建一個網格。在嵌套父網格的時候很好,但是當我嘗試嵌套另一個網格時,它顯示WebGrid.Colums有一些無效參數。 我有以下代碼如何在mvc3中使用jquery使用嵌套網格視圖

<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 
    ); 
    }), 

    )) 

回答

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 
      ); 
     }) 
    ) 
) 
相關問題