Monday, June 17, 2013

MVC: Intellisense for custom HtmlHelpers or if you want to avoid @using to import namespaces

If you write custom HtmlHelpers its quite tedious to have to add @using on top of each page. To be able to use your newly written htmlhelpers

to avoid this just find the web.config in your views folder and locate the following section:
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Optimization"/>
                <add namespace="System.Web.Routing" />
                <add namespace="SharpSolutions..MvcApplication.Helpers.BootStrap"/>
                <add namespace="SharpSolutions.MvcApplication.Helpers"/>

and add your custom namespace to it.

After you have done this reload your mvc project (or close Visual Studio and reopen it).