1

我想将嵌套列上的父源 PkId 称为 nestgrd.Column("Qty", format: (item) => Html.ActionLink((string)item.Product.ToString(), "FreeGiftQuantityViews", new { id = item.PkId } 但我无法调用。我怎样才能调用 new { id = item.PkId } as new {id= pkglist.item.PkId}

<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>
4

1 回答 1

0

不幸的是,你不能这样做。WebGrid 只会绑定到单个模型,并且由于列不是强类型的,因此您不能引用父类。

解决方案是创建一个 ViewModel,其中包含要在 WebGrid 中表示的所有数据,然后将 WebGrid 绑定到该 ViewModel。

于 2013-07-02T15:35:12.833 回答