我正在尝试在gird中创建一个网格。在嵌套父网格之前它很好但是当我尝试嵌套另一个网格时它表明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
);
}),
))
答案 0 :(得分: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
);
})
)
)