Search code examples
asp.net-mvc-5

How to add using statement in mvc 5 to all views


There are many examples of adding a using statement for all views in web.config for prior versions, but I have not found one for MVC 5.

Can someone give me an example?


Solution

  • Locate Web.config in the Views folder.

    Find the namespace section. It will already have namespaces for Mvc.

    Add the desired namespace:

    <namespaces>
        <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="MyNamespace" />
    </namespaces>