How do build a composite or template control in ASP.Net MVC, or the equivelant?

你说的曾经没有我的故事 提交于 2019-12-09 20:24:50

问题


In our current ASP.Net Webforms application we have several composite/template server controls that only exist for a common look and feel. For example, we have a panel control that has a title, a place for buttons related to the contents of the panel, and of course the contents. How is this best accomplished in MVC? RenderPartial doesn't get done what I need here. Should I still be using the same controls, but just on a view page? These controls don't really do anything on postback, they are only there for a common look and feel.

More Info:

We have a control in Webforms that implements ICompositeControl. We have a few properties on this control like Panel (type Panel), Buttons (again type Panel which would hold buttons) and a property Title of type string. Visually it looks like


回答1:


Templated partial views is the way to go.




回答2:


I'm a little hazy about the exact requirements here but i'f I understand this correctly then you want a control that has say title information with variable content such as static text, controls, images etc etc.

If I had to have a control that acted as a container for content, no matter what that content was, I think I'd consider a Html Helper that I could pass information to and it could make the assessment on what content to render.

It could then either call another helper, render a partial view or whatever.



来源:https://stackoverflow.com/questions/2799827/how-do-build-a-composite-or-template-control-in-asp-net-mvc-or-the-equivelant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!