I’m trying to add an action link to a grid. But only if a condition exists (the user is locked out). I can’t get this to work in mvc3 (razor). Nothing is displayed.
I’ve tried:
@Html.Telerik().Grid(Model.Users).Name("UserGrid").DataKeys(dataKeys => dataKeys.Add(o => o.UserName)).Columns(columns =>
{
columns.Template(s => Html.ActionLink(s.UserName, "Details", new { id = s.ProviderUserKey })).Title("Username (<i>click to edit</i>)");
columns.Template(s => { if (s.IsLockedOut) Html.ActionLink("Unlock", "UnlockUser", new { username = s.UserName }, new { @class = "unlockimage" }); });
}).Pageable().Sortable().Filterable()
and even when I remove the if(cond)… I can’t get the actionlink to display. However if I don’t use the lambda? it does work but is obviously displayed all the time.
columns.Template(s => Html.ActionLink("Unlock", "UnlockUser", new { username = s.UserName }, new { @class = "unlockimage" }) );
any help is greatly appreciated.
Check this online demo how which shows how to use template columns in Razor. Here is an excerpt: