tskulbru
tskulbru

Reputation: 2346

MVC3 WebGrid column definition problem

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 everyone can see what I want to be done here. (Im new to razor and WebGrid)

Upvotes: 0

Views: 817

Answers (1)

Michael Sagalovich
Michael Sagalovich

Reputation: 2549

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

Upvotes: 2

Related Questions