2011-09-02 93 views
0

我在其中一个视图中有一个WebGrid,如果用户是领导者,我想在其中一列显示图像。到目前为止,我目前没有工作。任何人都知道我可以做到这一点?MVC3 WebGrid列定义问题

我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) 
), 

即时得到过载错误。 希望大家可以看到我想在这里做什么。 (进出口新的剃须刀和的WebGrid)

回答

2

试试这个

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    
) 

查看更多有关代表在这里剃刀:http://haacked.com/archive/2011/02/27/templated-razor-delegates.aspx

+0

没有工作,我不认为你可以写剃刀一样的语法在webgrid定义里面 – tskulbru

+0

对不起,是的:)微小的修改应该可以工作,不是吗?只是把它定义为一些变量。 –

+0

你有没有例子?我试过了大概50种方法:P – tskulbru