Reputation: 2175
I have a problem with TagHelpers, they are not being resolved.
I have added Microsoft.AspNetCore.Mvc.TagHelpers to the project using NuGet, and it is showing as installed.
I have the _ViewImports.cshtml file, containing...
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
... in my Views/Shared folder.
The Index.cshtml view file has an entry in the head element...
<link rel="stylesheet" asp-href-include="lib/bootstrap/dist/css/*.min.css" />
The css files are in the referenced directory.
I have added...
app.UseStaticFiles();
... to the Configure() startup function.
ConfigureServices() also includes...
services.AddMvc();
When I run the app, and do a View Source on the received html, I can see the asp-href-include tag helper has not been resolved, it appears as it is in the cshtml file. There are no errors, and no exceptions occur.
I have tried restarting VS 2017, but no joy.
What have I missed that would stop tag helpers working but not generate errors? Also, how can I debug this?
Upvotes: 1
Views: 1875
Reputation: 2175
I had my _ViewImports.cshtml file in the /Views/Shared folder (which looks sane, right?).
However, this file must go in the /Views folder. (Note, each view can have it's own copy in a local folder).
Effectively, the @addTagHelpers directive was being ignored, because the _ViewImports.cshtml file was in the wrong place and not being picked up.
Solution was to copy the file up one directory from /Views/Shared to /Views.
Upvotes: 3