BrunoLM
BrunoLM

Reputation: 100361

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 in my class file the TagBuilder class is not visible.

How can I use TagBuilder in a Class Library project?

Upvotes: 20

Views: 14674

Answers (5)

clayRay
clayRay

Reputation: 743

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.

Upvotes: 0

Kirk Woll
Kirk Woll

Reputation: 77576

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.

Upvotes: 37

user595970
user595970

Reputation: 111

You also need a reference to System.Web.WebPages

Upvotes: 11

Nathan Anderson
Nathan Anderson

Reputation: 6878

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.

Upvotes: 0

Edward
Edward

Reputation: 131

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?

Upvotes: 0

Related Questions