下面的代码将在一个Web网格列中插入一个actionlink.
@{ View.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; var usersGrid = new WebGrid(source: Model,rowsPerPage: 40); } @usersGrid.GetHtml( tableStyle: "grid",headerStyle: "head",alternatingRowStyle: "alt",columns: usersGrid.Columns( usersGrid.Column(format: (item) => Html.ActionLink("Edit","Edit",new { id = item.Id})),usersGrid.Column("Surname") ) )
但是如果我交换这个行:@H_502_5@
usersGrid.Column(format: (item) => Html.CheckBox(item.Id)),
Error 4 The best overloaded method
match for
‘System.Web.Helpers.WebGrid.Column(string,
string,System.Func,bool)’ has some invalid
arguments.@H_502_5@
我不太明白两者之间的区别..为什么一个工作和另一个错误?@H_502_5@
最终的目标是能够勾选一些复选框,然后发送以打印他们的信息.@H_502_5@
解决方法
这对我来说最有效.
usersGrid.Column(header: "Print?",format: @<text><input name="Prints" type="checkBox" value="@item.ID" /></text>),
要感谢尼克·哈里斯,他的博客的评论中找到答案:
http://www.nickharris.net/2010/10/a-first-look-at-the-asp-net-mvc-3-webgrid/@H_502_5@