I have a WebGrid in one of my views, in one of the columns i want to show a image if the user is a leader. What I have thus far, doesn't work at the moment. Anyone know how I can do this?
The code of my troublerow:
grid.Column("FullName", header:"Name", format: (item) => (item.IsLeader())) ?
@<text><img src="@Url.Content("~/Content/Images/Leader.gif")" alt="" /></text> :
Html.ActionLink((string)item.FullName,"Index","Organization", new { area = "Catalogue" }, null)
),
Im getting overload error. Hope eve开发者_如何学Pythonryone can see what I want to be done here. (Im new to razor and WebGrid)
Try this
Func<dynamic, object> format = @<text>@{
if (item.IsLeader())
{
<img src="@Url.Content("~/Content/Images/Leader.gif")" alt="" />
}
else
{
<text>Html.ActionLink((string)@item.FullName,"Index","Organization", new { area = "Catalogue" }, null).ToString()</text>;
}}</text>;
grid.Column(
"FullName",
header:"Name",
format: format
)
See more about delegates in Razor here: http://haacked.com/archive/2011/02/27/templated-razor-delegates.aspx
精彩评论