在cshtml视图中包含(使用)命名空间 [英] include (using ) a namespace in cshtml view

查看:404
本文介绍了在cshtml视图中包含(使用)命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我正在写一个观点。我需要包含COM库命名空间的命名空间或引用。

@model ABCCOM.Documents

这行提示错误并要求我包含库引用。在我的控制器或模型中,我能够使用ABCCOM.Documents。

我找不到任何解决方案。请帮助

Dear All,
I am writing a view. I need to include a namespace or reference of COM library namespace.
@model ABCCOM.Documents
this lines gives error and asks me to include library reference. while in my controler or model I am able to use ABCCOM.Documents.
I am not finding any solution. Please Help

推荐答案

using指令根本不包含任何内容。它只为顶级类型引入默认/别名命名,没有别的。换句话说,您可以删除所有using指令,并且仍然可以通过编写全名来访问相同的类型,即包含命名空间名称的名称。请参阅:

https://msdn.microsoft.com/en-us /library/0d941h9d.aspx [ ^ ]。



了解名称空间与.NET的模块化无关是很重要的。 .NET中单独编译的真正单元是程序集及其模块。没有任何规则要求程序集和命名空间之间的任何对应关系:任何程序集都可以声明其类型和不同命名空间的数量,并且任何命名空间都可以在任意数量的程序集中使用。然而,混合使用诸如程序集和命名空间之类的不同概念是一些初学者的常见错误。



要在其他程序集中使用程序集,您需要<我>参考它。请参阅:

https:// msdn .microsoft.com / zh-CN / library / 8wxf689z%28v = vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/ms973231.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/xwb8f617%28v=vs.110%29.aspx [ ^ ],

https ://msdn.microsoft.com/en-us/library/s1sx4kfb%28v=vs.110%29.aspx [ ^ ]。



此外,程序集可以在运行时加载并通过反射使用。但这是另一个故事...



-SA
The "using" directive does not "include" anything at all. It only introduces default/alias naming for top-level types, nothing else. In other words, you can remove all "using" directives and still be able to access the same very types by writing their full names, that is, then names including namespace names. Please see:
https://msdn.microsoft.com/en-us/library/0d941h9d.aspx[^].

It's important to understand that namespaces have nothing to do with modularity of .NET. The real units of separate compilation in .NET are assemblies and their modules. There are no any rules requiring any correspondence between assemblies and namespaces: any assembly can declare its type in and number of different namespaces, and any namespace can be used in any number of assemblies. Nevertheless, mixing up such different notions as assemblies and namespaces is a usual big mistake in some of the beginners.

To use the assembly in other assembly, you need to reference it. Please see:
https://msdn.microsoft.com/en-us/library/8wxf689z%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/ms973231.aspx[^],
https://msdn.microsoft.com/en-us/library/xwb8f617%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/s1sx4kfb%28v=vs.110%29.aspx[^].

Also, assemblies can be loaded during runtime and used through reflection. But this is another story…

—SA


这篇关于在cshtml视图中包含(使用)命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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