Q:

MVC3 Webgrid formatting

I am using Webgrid for paging. Is there a way to access each item? For example, i want to add some links column if the the item of the model meets a certain criteria. 
For example:
@grid.GetHtml(columns: grid.Columns(
     /If (item.name == "test")// statement to test condition here{
       grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { name = item.name })),
       }
       else{
       grid.Column(format: (item) => Html.ActionLink("Detail", "Detail", new { name = item.name })),
        }
        grid.Column("FirstName"),
        grid.Column("LastName"),
        grid.Column("EmailAddress")
    )

can this be done with webgrid? if not, what are other alternatives?

A:

You should be able to put a condition like that inside the format parameter itself.  Like this:
@grid.GetHtml(columns: grid.Columns(
    grid.Column(format: item => 
        (item.name == "test") ?
            Html.ActionLink("Delete", "Delete", new { name = item.name })
            : Html.ActionLink("Detail", "Detail", new { name = item.name })
    ))
)

Note that, if you need to for a more complex scenario, you can also put an anonymous function inside the format lambda.  It should return an MvcHtmlString (as in ActionLink, etc):
grid.Column(format: item => 
{
    if (item.name == "test")
    {
        return Html.ActionLink("Delete", "Delete", new { name = item.name });
    }
    else
    {
        return Html.ActionLink("Detail", "Detail", new { name = item.name });
    }
})

