How to add using statement in mvc 5 to all views

2019-08-27 21:07发布

问题:

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?

回答1:

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>