I'm working on an MVC 5 project using VB.NET and EF 6. I have added an EditorTemplates nuget package which relies upon Custom Global Helpers.
In C# I can merely add new helpers wherever as a public static class
, then add the namespace to ~/Views/Web.config
and off I go. To the best of my knowledge C# and VB.NET differ here greatly.
After much battling with the compiler and Stack Overflow searching I found that I could get the custom helpers to work in views if placed them in the App_Code folder.
I used a Module with the <System.Runtime.CompilerServices.Extension>
attribute applied to each method. Then added to ~/Views/Web.config
and the App_code folder and compile.
Imports System.Web.Mvc
Public Module HtmlHelpers
<System.Runtime.CompilerServices.Extension>
Public Function HelperName(ByVal helper As HtmlHelper, hn As HelperName) As MvcHtmlString
Return MvcHtmlString.Create(hn.ToString())
End Function
End Module
This allows me to use the new custom helpers, but completely blocks out all of the in-built html helpers like DisplayFor, EditorFor and ActionLink.
Please correct me if I'm wrong. There seems to be no documentation whatsoever about this online, apart from confirming the issue, then ignoring it for over 5 years.
How can I use both? I'm at the end of my tether and losing faith in Microsoft's support/documentation.