MVC3 中的 WebGrid 列格式问题
我一直在尝试更改 WebGrid 中单个列的格式,但没有取得太大成功。该栏是这样的:
grid.Column(
columnName: "EmailAddress",
header: "Email Address",
format:(item) => Html.EmailLink(item.EmailAddress, item.EmailAddress, ""),
canSort: false
),
错误是:
“System.Web.Helpers.WebGrid.Column(string, string, System.Func, string, bool)”的最佳重载方法匹配有一些无效参数
我很困惑,因为方法签名匹配。另外,如果我将列更改为下面的内容,那么它可以正常工作,不会出现任何错误:
grid.Column(
columnName: "EmailAddress",
header: "Email Address",
format:(item) => new HtmlString(String.Format("<a href=\"mailto:{0}\" class=\"{2}\">{1}</a>", item.EmailAddress, item.EmailAddress, "")),
canSort: false
),
作为参考,EmailLink
是一个非常基本的 HtmlHelper
扩展方法:
public static IHtmlString EmailLink(this HtmlHelper helper, string emailAddress, string linkText, string linkClass) {
return new HtmlString(String.Format("<a href=\"mailto:{0}\" class=\"{2}\">{1}</a>", emailAddress, linkText, linkClass));
}
任何人都可以告诉我问题是什么这是,我该如何解决它?
I've been trying to change the format of a single column in a WebGrid without much success. Said column is this:
grid.Column(
columnName: "EmailAddress",
header: "Email Address",
format:(item) => Html.EmailLink(item.EmailAddress, item.EmailAddress, ""),
canSort: false
),
The error is:
The best overloaded method match for 'System.Web.Helpers.WebGrid.Column(string, string, System.Func, string, bool)' has some invalid arguments
I am confused as the method signature matches. Also, if I change the column to the below then it works without any errors:
grid.Column(
columnName: "EmailAddress",
header: "Email Address",
format:(item) => new HtmlString(String.Format("<a href=\"mailto:{0}\" class=\"{2}\">{1}</a>", item.EmailAddress, item.EmailAddress, "")),
canSort: false
),
For reference, EmailLink
is a very basic HtmlHelper
extension method:
public static IHtmlString EmailLink(this HtmlHelper helper, string emailAddress, string linkText, string linkClass) {
return new HtmlString(String.Format("<a href=\"mailto:{0}\" class=\"{2}\">{1}</a>", emailAddress, linkText, linkClass));
}
Can anyone tell me what the issue here is, and how I can solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由于 WebGrid 的丑陋和所有这些动态垃圾造成的。你需要一个演员:
话虽如此,请毫不犹豫地查看 MvcContrib Grid 或 < a href="http://www.telerik.com/products/aspnet-mvc/grid.aspx" rel="noreferrer">Telerik Grid 更好。
This is due to the ugliness of WebGrid and all this dynamic crap. You need a cast:
This being said don't hesitate to checkout MvcContrib Grid or the Telerik Grid which are far better.