The current version of the Razor Generator has a Generator parameter, which when used with the MvcHelper generator also creates a static method for helpers.
For example, add this line at the top of your CSHTML file (using the Visual Studio Custom Tool property set in RazorGenerator, of course):
@* Generator: MvcHelper, GeneratePrettyNames : true *@
A nice version of the names is not strictly necessary, but I think it should be the default to avoid these crazy long class names with underscores :-)
As you already know, the main advantage of this method is that you can share your helpers in separate assemblies. This is why I use Razor Generator in the first place.
Even inside the same assembly, you can leave your code outside the App_Code folder. However, this is not the best practice (at least for security), and the Visual Studio designer is confused. He believes that the method is still not static, but it does not work and works fine.
I prototype my helpers in the App_Code folder of the same site / assembly for speed, and then copy them to common components when they are tested. The reason I needed this solution was to create universal Bootstrap helpers without manually encoding each HTML fragment in an HtmlHelper, i.e. used with this solution by @chrismilleruk.
I believe that later, I may have to convert the CSHTML helpers to HtmlHelper manual encoding for speed. But for starters, with a large increase in development speed at the beginning, with the ability to copy and paste blocks of HTML code, I want to automate, and then improve and quickly debug them in the same format / editor.
Tony Wall Jul 24 '15 at 11:51 2015-07-24 11:51
source share