Telerik MVC Grid 的控制器侧栏绑定
我有一个使用 Telerik MVC 网格的部分视图,它的列绑定代码如下(非常部分视图):
.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.
现在我需要编写一个控制器操作以将网格中呈现的相同数据导出到 Excel,并且我需要基于相同角色的列包含/排除。我不想重复角色检查逻辑,所以我正在寻找一种方法来生成此处用于控制器中列绑定的数据,将其与 ViewData 一起传递,并在视图中使用它来动态绑定列。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这个示例会有所帮助。但有一个免责声明 - 这仍处于测试阶段,最终的 API 将从 更改
为
Perhaps this example would help. There is a disclaimer though - this is still in beta and the final API will change from
to