Search code examples
c#asp.net-mvcasp.net-mvc-3razorglobal-namespace

How do I use the C# Global namespace operator with a using directive in my View?


Having some trouble with my view in asp.net mvc. My using directive's namespace is clashing with the namespace of the view, causing compile errors in my Razor generated class. I had the same issue with the @model directive, but using the global:: alias fixed it. For some reason, doing the same on my @using causes a "The type or namespace 'global' could not be found..." error. Here is what I have right now:

@using SampleSpace.System.Items

@model global::SampleSpace.System.Items.Thing

I want to use

@using global::SampleSpace.System.Items

@model global::SampleSpace.System.Items.Thing

But the aforementioned error keeps occurring. Is there any trick to using global in a using directive in a view, or is there a reason it isn't allowed?


Solution

  • Turns out the simplest way to overcome this is to adjust the Custom Tool Namespace under the files Properties. You can change this to whatever you'd like to avoid any conflicts.