How to put a condition (if else) in webgrid column?
@grid.GetHtml(tableStyle: "table table-bordered",
columns: grid.Columns(
grid.Column("RealName", "Name"),
grid.Column("UserName", "Email")
))
I have to show the Email Column based on a condition, How to do this?
You can try this
@{
var gridColumns = new List<WebGridColumn>();
gridColumns.Add(grid.Column(format: (item) => Html.ActionLink("Select", "Details")));
if (true)
{
gridColumns.Add(grid.Column(format: (item) => Html.ActionLink("Edit", "Edit")));
}
gridColumns.Add(grid.Column("UserName", "name"));
gridColumns.Add(grid.Column("RealName", "RealName"));
}
@grid.GetHtml(columns: grid.Columns(gridColumns.ToArray()));