MvcContrib 网格和显示/编辑模板
有没有人遇到过将 ./Views/Shared/DisplayTemplates 和 ./Views/Shared/EditTemplates 与 MvcContrib.UI 网格一起使用的好解决方案?
我想我可以连接一个 CustomItemRenderer,但我更愿意能够做类似的事情:
<% Html.Grid<Person>(Model.People)
.Sort(new GridSortOptions {Column = Model.Column, Direction = Model.Direction})
.Columns(column =>
{
column.For(e=>e.Name);
column.DisplayFor(e=>e.StartDate); // <-- I'd like to do this for DateTime.asxc
}).Render();
%>
网格中可能已经有一些东西可以做到这一点,但我只是还没有找到它。任何帮助将不胜感激。
谢谢,
哈尔
Has anyone come across a good solution for using ./Views/Shared/DisplayTemplates and ./Views/Shared/EditTemplates with the MvcContrib.UI Grid?
I guess I could wireup a CustomItemRenderer, but I would much rather be able to do something like:
<% Html.Grid<Person>(Model.People)
.Sort(new GridSortOptions {Column = Model.Column, Direction = Model.Direction})
.Columns(column =>
{
column.For(e=>e.Name);
column.DisplayFor(e=>e.StartDate); // <-- I'd like to do this for DateTime.asxc
}).Render();
%>
There may already be something in Grid to do this and I just haven't found it yet. Any help would be greatly appreciated.
Thanks,
Hal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过修改 GridRenderer 和 GridColumn 类中的源代码实现了这一点。 GridColumn 中的更改是添加以下函数:
然后 GridRenderer 中的更改是在 RenderItem 函数中进行如下更改:
一旦执行此操作,网格将使用找到的模板。我只使用 DisplayTemplates 进行了测试,因为这就是我所需要的,但它也应该适用于 EditorTemplates,只需稍作更改。
I have acheived this by modifying the source code in the GridRenderer and GridColumn classes. The change in GridColumn is to add the following function:
Then the change in GridRenderer is in the RenderItem function to be changed as follows:
Once you do this the grid will use the templates found. I have only tested with DisplayTemplates as this is all I need but it should also work for EditorTemplates with a slight change.
我创建了这个扩展方法:
用法如下所示:
I have created this extension method:
Usage looks like following:
实际上你可以这样做:
这种方法的问题是整个模型将传递给部分模型,而不仅仅是属性。
Actually you could do this:
The problem with this approach is that the whole model will be passed to the partial and not simply the property.