[英]How to use TagBuilder in a Class Library project?
I am trying to use TagBuilder
in a Class Library project. 我想在类库项目中使用
TagBuilder
。 I have added references to System.Web
and System.Web.Mvc
(v3), but in my class file the TagBuilder
class is not visible. 我添加了对
System.Web
和System.Web.Mvc
(v3)的引用,但在我的类文件中, TagBuilder
类不可见。
How can I use TagBuilder
in a Class Library project? 如何在类库项目中使用
TagBuilder
?
In Asp.Net MVC 3, it is located in: 在Asp.Net MVC 3中,它位于:
c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.dll
In Asp.Net MVC 4, it is located in: 在Asp.Net MVC 4中,它位于:
c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll
So make sure you have a reference to that dll. 所以请确保您有对该dll的引用。
您还需要对System.Web.WebPages的引用
对于早期版本的Asp.Net MVC,这些答案都是正确的,但是现在最好也是最简单的方法就是使用NuGet Package Manager /“管理NuGet包来解决方案......”并安装最新版本的Microsoft.Aspnet.Mvc in你的项目。
If you added the DLL (in System.Web.Mvc.dll), and the namespace, it should be visible to you as a class. 如果您添加了DLL(在System.Web.Mvc.dll中)和命名空间,则它应该作为类可见。 Have you added the code above?
你有没有添加上面的代码?
Make sure you have a using
statement at the top of your file that references the System.Web.Mvc
namespace. 确保文件顶部有一个引用
System.Web.Mvc
命名空间的using
语句。 Since you have the reference added you should be good to go. 既然你已经添加了参考文献,那么你应该很高兴。 Have a look at the article ' Using the TagBuilder Class to Create HTML Helpers ' for more information and an example.
有关更多信息和示例,请查看文章“ 使用TagBuilder类创建HTML帮助程序 ”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.