Search code examples
razorasp.net-coreasp.net-core-tag-helpers

Can I use TagHelper in ASP.NET Web Aplication (.Net Framework)?


Can I use TagHelper in project ASP.NET Web Application (.Net Framework)?

I use VS 2017 and reference NuGet package Microsoft.AspNetCore.Mvc.TagHelpers. In Views\_ViewStart.cshtml add line @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers but I get Error CS0103 The name 'addTagHelper' does not exist in the current context. Template project which I use is MVC.

When I create project ASP.NET Core Web Application (.NET Framework) everything works good.

Does TagHelpers are restricted to Core projects?


Solution

  • Tag helpers is a new feature introduced in ASP.NET MVC Core 1.0 (earlier called as MVC 6) to prove readability of razor code. Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.

    As you can see, we need to add Microsoft.AspNetCore.Mvc.TagHelpers NuGet package to enable tag helpers in ASP.NET Core application. This package is not compatiable ASP.NET Web Application (.Net Framework). Hence, to use tag helpers select one of the ASP.NET Core application template visual studio.

    For more information, refer official documentation here.