C# 无法从';lambda表达式';至';system.func动态对象';MVC3剃须刀
在我的视图页面中,我得到了WebGrid.column错误的上述错误和“无效参数” //看法C# 无法从';lambda表达式';至';system.func动态对象';MVC3剃须刀,c#,asp.net-mvc-3,razor,webgrid,C#,Asp.net Mvc 3,Razor,Webgrid,在我的视图页面中,我得到了WebGrid.column错误的上述错误和“无效参数” //看法 @{ WebGrid grid = new WebGrid(Model.LoadProductDetails()); @grid.GetHtml( tableStyle: "grid", fillEmptyRows: false, headerStyle: "gvHeading", alternatingRowSt
@{
WebGrid grid = new WebGrid(Model.LoadProductDetails());
@grid.GetHtml(
tableStyle: "grid",
fillEmptyRows: false,
headerStyle: "gvHeading",
alternatingRowStyle: "gvAlternateRow",
rowStyle: "gvRow",
footerStyle: "gvFooter",
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("ProductId",header: "ID"),
grid.Column("ProductName",header: "Product"),
grid.Column("Price"),
grid.Column("Qunatity"),
grid.Column("ReorderLevel", header: "R.O.L."),
grid.Column("ContactusId", header: "Action", canSort:false, format: @<text> @Html.Raw("<img src='/img/edit.png' title='Edit' onclick='EditProduct("+ item.ProductId ")' />") @Html.Raw("<img src='/img/delete.png' title='Delete' onclick='DeleteProduct("+ item.ProductId +")' />") </text>)
})
}
@{
WebGrid=newWebGrid(Model.LoadProductDetails());
@grid.GetHtml(
表样式:“网格”,
fillEmptyRows:false,
headerStyle:“gvHeading”,
alternatingRowStyle:“GVAlternativeRow”,
行样式:“gvRow”,
页脚样式:“gvFooter”,
模式:WebGridPagerModes.All,
第一个文本:“,
lastText:“Last>>”,
列:新[]{
grid.Column(“ProductId”,标题:“ID”),
grid.Column(“产品名称”,标题:“产品”),
网格栏(“价格”),
网格柱(“质量”),
网格栏(“ReordLevel”,标题:“R.O.L.”),
grid.Column(“ContactusId”,标题:“Action”,canSort:false,格式:@@Html.Raw(“”@Html.Raw(“”))
})
}
错误被抛出到格式附近的最后一列(ContactUsId):。我错在哪里
请帮忙。我的评论是:看起来您正试图将客户端HTML注入服务器端函数调用(这反过来会生成客户端输出)。这与MVC的工作方式相反(代码注入HTML页面)。您需要将这些@转换为C#字符串。然后可以在服务器端对其进行处理,生成的GetHtml方法将最终结果注入到输出中 例子:类似这样的东西
看起来您正试图将客户端HTML注入到服务器端函数调用中(这反过来会生成客户端输出)。这与MVC的工作方式相反(代码注入HTML页面)。您需要将这些
@
转换为C#字符串。然后可以在服务器端对其进行处理,生成的GetHtml
方法将最终结果注入到输出中。@TrueBlueAussie:您可以共享一段代码吗?当然可以。下面的示例。错误在哪一行?正如我在安塞尔所说的,我为任何拼写错误道歉。这是为了给您指出正确的方向,而不是为您编写所有代码:)最后一列中的同一行。
@{
string template = "<text><img src='/img/edit.png' title='Edit' onclick='EditProduct("+ item.ProductId + ")' /><img src='/img/delete.png' title='Delete' onclick='DeleteProduct("+ item.ProductId +")' /></text>";
WebGrid grid = new WebGrid(Model.LoadProductDetails());
@grid.GetHtml(
tableStyle: "grid",
fillEmptyRows: false,
headerStyle: "gvHeading",
alternatingRowStyle: "gvAlternateRow",
rowStyle: "gvRow",
footerStyle: "gvFooter",
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("ProductId",header: "ID"),
grid.Column("ProductName",header: "Product"),
grid.Column("Price"),
grid.Column("Qunatity"),
grid.Column("ReorderLevel", header: "R.O.L."),
grid.Column("ContactusId", header: "Action", canSort:false, format: template)
}
string template = string.format("<text><img src='/img/edit.png' title='Edit' onclick='EditProduct({0})' /><img src='/img/delete.png' title='Delete' onclick='DeleteProduct({0})' /></text>", item.ProductId);