简体   繁体   English

如何在类库项目中使用TagBuilder?

[英]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.WebSystem.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.

相关问题 如何在类库项目中使用Autofac? - How to use Autofac in a class library project? TagBuilder AddCssClass顺序,添加到开头,如何在结尾添加新类? - TagBuilder AddCssClass Order, Adds to Beginning, how to Add New Class at the End? 如何在类库项目类型中使用ConfigurationManager类 - How to use ConfigurationManager Class in a Class Library Project type 如何使用TagBuilder创建文档类型 - How to create a doctype with TagBuilder 如何在Windows Phone类库项目中使用ResourceDictionary - How to use ResourceDictionary in Windows Phone class library project 如何从Webforms Web应用程序项目中使用Razor类库 - How to use Razor Class Library from a Webforms Web Application Project 如何在MVC 5的类库项目中使用Entity Framework 6代码优先 - How to use Entity Framework 6 Code First in Class Library Project with MVC 5 如何在另一个项目或类库中使用 appsettings.json - How to use appsettings.json in another project or class library 如何在项目中使用C#类库? - How do I use a C# Class Library in a project? 如何在UWP的类库项目中使用Resources.resw? - How to use Resources.resw in Class library project in UWP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM