What is the equivalent of Usercontrol in ASP.NET MVC?

Asked

Viewed 670 times

4

In Web Forms we have UserControl. These controls have a code-Behind and a layout. They can be used in different projects/solutions without depending on other things.

I want to create a control that displays various elements and some links/buttons that "trigger an event". I do not want this control to be linked to my site, I want to be able to reuse it in other websites.

What is the equivalent in MVC? It is possible to compile the Controller and the View in a DLL and use in another project?

2 answers

5


What suits you is a Htmlhelper (Creating custom HTML Helpers).

The two most common ways to create reusable components in ASP.NET MVC are partial views and html helpers. Unlike the views and partial views, the html helpers are classes/methods implemented like any other in your project. Their role is already to generate the final HTML, as opposed to a view that needs to be processed. So distributing them in a DLL is something totally natural.

Contrary to what many people think, html helpers can provide more complex components (e.g.: Webgrid).

P.S.: Theoretically it would be possible to distribute a partial view in a DLL since in the process they are compiled. But if that’s even possible, I believe it’s not supported by MVC, because I’ve never seen any documentation or practice about.

0

  • 1

    Welcome Rodrigo. As a Q&A site, what matters are the questions and answers that are contained here. Relevant information posted here will be useful for indexing searchers so that others will find the content in the future. Also when the answer has basically only one link, it may become outdated and in the future no longer contain anything relevant to this question or even disappear. In addition, we are discussing this type of answer here: http://meta.answall.com/questions/42/queremos-respostas-que-contenham-somente-links

Browser other questions tagged

You are not signed in. Login or sign up in order to post.