Asp.Net Mvc 2 可重用部分?
我想知道,是否有与 Asp.Net MVC 的 Monorail View 组件等效的组件?
我想做的是渲染一些依赖于类的复杂 UI,所以假设我们在列表视图中,我想将一个对象传递给此 ViewComponent 等效项,并且它将将该对象作为参数并渲染复杂的 UI我的 UI 允许我在视图中做其他事情。在 Asp.Net MVC 中执行此操作的最佳方法是什么?
由于这是一个复杂的 UI,我更愿意编写一次,因此模板并不是我真正想要的方式,因为这意味着我将遇到可维护性问题。
我看到的一些选项(我即将开始尝试)是:
- Html.RenderAction in the futures
- Subcontroller
但是我想知道是否还有其他选项,或者对于这个特定场景,一个选项是否比另一个更好
I wonder, is there an equivalent of the Monorail View components for Asp.Net MVC?
What I m trying to do is render some complex UI that depends on a class, so say we are in a List view, I want to pass an object to this ViewComponent equivalent and that it will take the object as a parameter and render the complex UI for me allowing me to do other stuff in the view. What would be the best way to do that in Asp.Net MVC?
Since this is a complex UI I would prefer to write it once, hence templates are not really the way I would like to go, as it will mean I ll have maintainability issues.
Some options I saw ( and I m about to start trying) are:
- Html.RenderAction in the futures
- Subcontroller
However I d like to know if there is anything else or if one is better than the other for this particular scenario
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用
查看此页面< /a>
You can use
Have a look at this page
渲染部分怎么样?这似乎符合要求。
What about RenderPartial? That seems to fit the bill.
请查看 MVC 2 预览中的 DisplayTemplates 和 EditorTemplates。
Please take a look at DisplayTemplates as well as EditorTemplates in MVC 2 preview.
或者您可能需要模板化助手?
Or maybe you want Templated Helpers?
MvcContrib InputBuilder 有类似的东西。
尽管您可以自己编写:
注意递归。当然,您必须在 switch(PropertyType) 内添加集合支持等...但这并不难。您还可以检查属性上的 UIHint 以呈现部分。很多可能性,一切都在你的掌控之中;-)
MvcContrib InputBuilder has something similar.
Though you may just write your own:
Notice recursion. Of course you will have to add collections support, etc... inside switch(PropertyType)... but this is not that hard. You may also check for UIHint on the property to render partials. A lot of possibilities and all under your control ;-)