I'm creating my first MVC.Net application and I find myself including @using Gideon.Core.Mvc;
on almost every page. Is it possible to add it by default to all pages?
In Asp.Net I'm able to add default stuff for controls to the web.config, hopefully it can be done for MVC.Net as well.
Add them in the
Views/Web.config
. Add your namespace to the bottom:For .Net Core Users if you create a vanilla web project you can import default namespaces by adding the
File within your Pages folder.
And define your default namespaces within.
You can add them in the
<system.web.webPages.razor>
section inViews/Web.config
.Here is the default:
Since this question is high on google, let me add an alternative solution which is area compatible.
Create a new class called
PreApplicationStart
(or any other name you want).In
Properties\AssemblyInfo.cs
add following line:With this the namespace is available in every view in the project (including views within areas). Adding the namespace to
web.config
has this flaw, that if you use areas, you end up having to add the namespace to everyweb.config
file in each area.