I have a partial view that uses a Telerik MVC Grid, and it has column binding code as follows (very partial view):
.Columns(column =>
{
column.Bound(model => model.PlannedFinishDate).Title("Planned Date").Format("{0:dd/MM/yyyy}").Width(83);
column.Bound(model => model.Province).Width(70);
if (Roles.IsUserInRole("Controller") == true)
{
column.Bound(model => model.InstallerName).Width(85);
column.Bound(model => model.InstallerAccepted).Title("Accepted").Width(45);
column.Bound(model => model.KitShippedDescription).Width(70);
}
// etc. etc.
Now I need to write a controller action to export the same data as rendered in the grid to Excel, and I need the same role based column inclusion/exclusion. I don't want to duplicate the role checking logic, so I'm looking for a way to generate the data used here for column binding in the controller, pass it with the ViewData, and use it in the view to dynamically bind the columns.