Is it possible to put the declarative html helpers in an assembly different than the application web project?
Currently, the only place where I know I can put my declarative html helpers is in the folder 'App_Code' of my application web project.
After a couple of months of development, I now have a lot of these declarative html helpers and the only one solution I have to shared it among all my projects is with a the very bad practice of 'Copy Paste Driven Development'.
Any other ways?
P.S.
Just not to be confused by the definition of what is declarative html helpers, here is a code sample to makes the difference compared to c# extensions that extend the System.Web.Mvc.Html type:
@using Microsoft.Web.Mvc.Html
@helper YesNoRadioButton(System.Web.Mvc.HtmlHelper html, string name, bool value, bool disable = false)
{
@html.RadioButton(name, true, value, id: name.Replace(".", "_") + "_Yes", disabled: disable) @:Oui
@html.RadioButton(name, false, !value, id: name.Replace(".", "_") + "_No", disabled: disable) @:Non
}
@helper YesNoRadioButton(System.Web.Mvc.HtmlHelper html, string name, bool? value, bool disable = false)
{
@html.RadioButton(name, true, value.HasValue && value.Value, id: name.Replace(".", "_") + "_Yes", disabled: disable) @:Oui
@html.RadioButton(name, false, value.HasValue && !value.Value, id: name.Replace(".", "_") + "_No", disabled: disable) @:Non
}
Make a class library of those helpers and then share it among projects.It will be better if you put your helpers in a custom created folder Helpers
. This is what I do.
You can refer to this answer: Where shall I put my utilities classes in a ASP.NET MVC3 application?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With