I have an ASP.NET MVC control which has to do some work to format some information from the model. This results in fairly complicated logic to build up the desired HTML. I want to be able to re-use this code multiple times within the control. Is there a way I can create a method (or something similar) within the control that would do this? I know that I can create UI helper methods, but wouldn’t these be visible to every control?
What is the best practice for create a helper method for an ASP.NET MVC control? Thanks!
Additional Info:
We are using ASP.NET MVC 3, but I don’t think we use Razor much, so it might not be an option.
Best place for encapsulating your complex UI reusable code is HtmlHelper extensions:
Usage (in partial view or full view):
UPDATE
OK, it seems this question is dead. Anyway, just to clarify more, if you look at the MVC itself, all common UI logic has been implemented as HtmlHelper extensions, such as
DropDownFor,DisplayFor,TextboxFor, etc