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?
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?
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>
For ASP.NET Core MVC you can also add inside _ViewImports.cshtml
a statement such as this at the top if you needed to add the models class to your views.
@using Myprojectnamespace.Models