开发者

MVC3 WebGrid column definition problem

开发者 https://www.devze.com 2023-04-02 14:51 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消