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?
You should be able to put a condition like that inside the
formatparameter itself. Like this:Note that, if you need to for a more complex scenario, you can also put an anonymous function inside the
formatlambda. It should return anMvcHtmlString(as inActionLink, etc):