I wrote a UrlHelper and in every view I need to include an using clause:
@using MyWebPage.Helpers
Is there way to avoid it? That would be great if this import automatically.
I added this in web.config as below:
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="MyWebPage.Helpers" />
</namespaces>
</pages>
But it wouldn't solve my problem.
There are 2 web.configs in the project.
You need to include the namespace in proper web.config which is for views. Once you include it in proper namespace you don't have to include it in every page.
<system.web.webPages.razor>
<host ....>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="MyWebPage.Helpers" />
</namespaces>
</system.web.webPages.razor>
</pages>
Add the namespace into Views/web.config
, close all cshtml files, reopen them, voila.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With