We’re in the process of transferring a big WebForms app to MVC.
In the WebForms app we have some reusable controls (.ascx). For instance, a TextBox that shows username suggestions as you type. The control adds some JS/CSS to the page, has some server-side logic and custom properties (like SelectedUserID).
What should it be in an MVC app? How do I encapsulate those things into one reusable entity in an MVC app? Maybe a partial view? But you can’t add, say, JS/CSS to the page’s <head> from a partial view (preferably, with a check that it’s not already been added)… Also, how do I return something like the mentioned SelectedUserID in a partial view?
To rephrase the question – how would you implement such a control in an MVC app?
PS. I know you can still use .ascx user-controls in MVC apps but it seem a “hacky/legacy” way. What is the “legitimate” option?
The best solution I’ve found so far is Razor declarative helpers. They fit awesomely.
Related question: Razor: Declarative HTML helpers
Related note: you can’t use @Html helper inside a declarative helper but there’s a workaround: https://stackoverflow.com/a/5557503/56621