2013-06-30 41 views
1

我想在嵌套列上調用父項源的PkId作爲nestgrd.Column(「Qty」,格式:(item)=> Html.ActionLink((string)item。 Product.ToString(),「FreeGiftQuantityViews」,new {id = item.PkId}但我無法調用。我如何將新的{id = item.PkId}作爲新的{id = pkglist.item.PkId}調用如何通過嵌套GridView的內容調用父Gridview的項目Id

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

     var grid = new WebGrid(Model.pkglist, rowsPerPage: 10, canSort: false, canPage: false, ajaxUpdateContainerId: "lgrid"); 

    } 

@grid.GetHtml(
    tableStyle: "lgrid", 
    headerStyle: "head", 
    alternatingRowStyle: "alt", 
    columns: grid.Columns(
    grid.Column("S.N.", format: @<text>@{count++;}@count</text>, style: "sn"), 
    grid.Column("PkId", format: @<text>@item.PkId</text>), 
    grid.Column("Package Name", format: @<text>@item.PackageName</text>), 
    grid.Column("Product", format: @<text>@item.Product</text>), 
    grid.Column("Access", format: @<text>@item.Access</text>), 
    grid.Column("Rate", format: @<text>@item.Rate</text>), 
    grid.Column("Remarks", format: @<text>@item.Remarks</text>), 
    grid.Column("Edit", format: (item) => Html.ActionLink("Edit", "EditPackage", new { id = item.PkId }, new { @class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "Edit" })), 
    grid.Column("Delete", format: (item) => Html.ActionLink("Delete", "DeletePackage", new { id = item.PkId }, new { @class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "Delete" })), 
    grid.Column("Free Package Lists", format: row => 
     { 
      WebGrid nestgrd = new WebGrid(row.plsst); 
      return nestgrd.GetHtml(
       columns: nestgrd.Columns(
        nestgrd.Column("FreePackageDetails", format: (item) => Html.ActionLink((string)item.Product.ToString(), "FreePackageDetails", new { id = item.PkId }, new { @class = "openDialog", data_dialog_id = "EmailDialog", data_dialog_title = "Details" })), 
        nestgrd.Column("Free Gift", format: (item) => Html.ActionLink((string)item.Product.ToString(), "FreeGiftViews", new { id = item.PkId }, new { @class = "openDialog", data_dialog_id = "EmailDialog", data_dialog_title = "Details" })), 
        nestgrd.Column("Qty", format: (item) => Html.ActionLink((string)item.Product.ToString(), "FreeGiftQuantityViews", new { id = item.PkId }, new { @class = "openDialog", data_dialog_id = "EmailDialog", data_dialog_title = "Details" })) 


       ), 
       displayHeader: false 
      ); 
     }) 
                                 )) 
</div> 

回答

0

不幸的是,你不能這樣做。的WebGrid只會綁定到一個單一的模式,因爲該列不強類型,你不能引用一個父類。

的解決方案是創建一個包含的ViewModel您想要在WebGrid中表示的所有數據,然後將您的WebGrid綁定到該ViewModel。