9

Is there a way to do an extern alias inside a razor (MVC3) view?

I have two versions of the same assembly (i.e. 1.0 and 2.0) with a type that has the same name and namespace and I need a way to specify the newer one in the razor view.

I've tried:

@extern

and:

@{ extern alias MyAlias; }

But neither of those worked.

Jesus is Lord
  • 14,323
  • 10
  • 60
  • 90

1 Answers1

0

In the "web.config" file in "Views" directory of your project.Find this section.

<system.web.webPages.razor>
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      .
      .
      <!-- etc -->
    </namespaces>
  </pages>
</system.web.webPages.razor>

you can add your custom namespace like this:

<add namespace="My.Custom" />

That will add the namespace to all of Razor(.cshtml or .vbhtml) files.

Brahim Boulkriat
  • 974
  • 2
  • 8
  • 20
  • 2
    This is not what he's asking. He wants an alias. Doing what you suggest would have the same result as `@using My.Custom` in the view itself. – Ethan Reesor Oct 02 '14 at 21:09