开发者

How to use TagBuilder in a Class Library project?

I am trying to use TagBuilder in a Class Library project. I have added references to System.Web and System.Web.Mvc(v3), but i开发者_运维问答n my class file the TagBuilder class is not visible.

How can I use TagBuilder in a Class Library project?


In Asp.Net MVC 3, it is located in:

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:

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.


You also need a reference to System.Web.WebPages


If you added the DLL (in System.Web.Mvc.dll), and the namespace, it should be visible to you as a class. 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. 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.


Those answers are all correct for older versions of Asp.Net MVC, but these days it's probably best and easiest to just use NuGet Package Manager / "Manage NuGet Packages for Solution.." and install the latest version of Microsoft.Aspnet.Mvc in your project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜