Reputation: 3580
According to the documentation:
The
@addTagHelper
directive makes Tag Helpers available to the view. In this case, the view file isViews/_ViewImports.cshtml
, which by default is inherited by all view files in the Views folder and sub-directories; making Tag Helpers available.
So I imported the Tag Helpers in the Views\_ViewImports.cshtml
:
@using MyProject
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
and they work well on files inside the Views
folder.
However, in the file Views/Home/Index.cshtml
, I don't have support for Tag Helpers, neither are they correctly rendered as links. When I copy the _ViewImports.cshtml
into the folder Views/Home
, everything works as expected.
So what am I missing?
Update
So what am I missing? That my _ViewImports.cshtml
was put in the folder Views/Shared
(d'oh). After moving it to Views
, the TagHelpers work as intended everywhere.
Upvotes: 7
Views: 2676
Reputation: 2687
I tried a blank new ASP.NET Core 1.0 project and add it is working fine under Views/Home/Index.cshtml
view. This is what you have to do (Make sure that it is available):
Add to following package and tool section into your project.json
file:
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
and
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
Create an _ViewImports.cshtml
file under Views folder (You have one already) with the contents that you have mentioned.
Note: You may have to restart your VS to get it working.
Upvotes: 4