简体   繁体   English

有没有办法在剃刀(MVC3)视图中做一个`extern alias`?

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

Is there a way to do an extern alias inside a razor (MVC3) view? 有没有办法在剃刀(MVC3)视图中进行extern alias

I have two versions of the same assembly (ie 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. 我有两个版本的相同程序集(即1.0和2.0),其类型具有相同的名称和命名空间,我需要一种方法来在剃刀视图中指定较新的版本。

I've tried: 我试过了:

@extern

and: 和:

@{ extern alias MyAlias; }

But neither of those worked. 但这些都没有奏效。

In the "web.config" file in "Views" directory of your project.Find this section. 在项目的“Views”目录中的“web.config”文件中。查找此部分。

<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. 这将为所有Razor(.cshtml或.vbhtml)文件添加名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM