隐式命名空间和服务引用 [英] Implicit namespace and service reference

查看:98
本文介绍了隐式命名空间和服务引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了命名空间中的类的服务引用的的服务引用的 myNameSpace对象的,包含了一些数据类的定义。这导致了我的CSHTML文件的语法如下。

I've got a service reference of type ServiceReference in the namespace MyNamespace, containing some data classes' definitions. That leads to the following syntax in my CSHTML file.

@foreach(MyNamespace.ServiceReference.MyDataType blopp in ViewBag.Blopps) ...

这是不到方便,我希望能够去这样代替。

This is less than convenient and I'd like to be able to go like this, instead.

@foreach(MyDataType blopp in ViewBag.Blopps) ...

在一个CS文件,我想申请的使用的为这一点,但什么建议对CSHTML文件的方法呢?

In a CS file, I'd apply using for this but what's recommended approach for the CSHTML file?

修改

当然,除了 @using MyNamespace.ServiceReference; :)

推荐答案

使用:

@using MyNamespace.ServiceReference

编辑:

由于您的问题编辑您指定,除了 @using ,您可以在 web.config中添加引用文件,但它们将适用于所有的意见。

Since in your edited question you specified, besides @using, you can add the references in web.config file but they will be available for all the views.

<system.web.webPages.razor>
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <!-- Add following with others -->
      <add namespace="MyNamespace.ServiceReference" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

这篇关于隐式命名空间和服务引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆