You can write a helper method that will generate columns dynamically based on user roles:
public static class GridExtensions { public static WebGridColumn[] RoleBasedColumns( this HtmlHelper htmlHelper, WebGrid grid ) { var user = htmlHelper.ViewContext.HttpContext.User; var columns = new List<WebGridColumn>();
and then, in your opinion:
@{ var grid = new WebGrid(Model); } @grid.GetHtml(columns: grid.Columns(Html.RoleBasedColumns(grid)))
source share