0

I have a DLL that contains extension methods and I want to be able to use them in all my views without having to manually add the @using MyLongNameSpaceHere in each of my files.

Is there a way to globally load a namespace in all my Razor engine view?

5
  • @Igor Nop beacuse I want to get rid of the @Using call. Commented Apr 1, 2016 at 19:54
  • @KhairulIslam Nop beacuse the awser you point out is in c# file and I'm in a Razor view. Commented Apr 1, 2016 at 19:54
  • @Muffun - yes, see the 2nd answer in the list. It explicitly shows how to use the web.config. Answer by Javad_Amiry Commented Apr 1, 2016 at 19:54
  • @Igor Indeed. I had only check the accepted answer. Commented Apr 1, 2016 at 19:56
  • @KhairulIslam - that previous question is not what Muffun is asking though. Commented Apr 1, 2016 at 19:59

1 Answer 1

4

In the "~/views/web.config" file, use something as following:

<system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc.Ajax" /> </namespaces> </pages> </system.web.webPages.razor> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.