Single using statement, multiple views MVC

I've written several extension methods (HTML helpers) and would like to use them in many views, this ...

@using My.Extensions.Namespace



... obviously works. But that means including the operator using

in each separate view (there will be many).

If that's the only approach that's fine, but I'm wondering if there is a way to use this namespace "globally" without having to declare it on every separate view.


source to share

1 answer

You can enable it via a file webconfig

inside a folder Views


    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <add namespace="My.Extensions.Namespace"/>


Every namespace that we need to reference in the Razor view must be declared either this way or in the view itself using an operator @using




All Articles