I'm in the process of getting to grips with ASPNET CORE [version 1.1, using VS2017 Community, version 15.1 (26403.3)]I've created a working ViewComponent called UserDetails
(abbreviated below):
namespace AdminConsole.ViewComponents
{
[ViewComponent(Name = "UserDetails")]
public class UserDetailsViewComponent : ViewComponent
{ ...does stuff... }
and I can invoke it successfully in a view by using
@await Component.InvokeAsync("UserDetails")
I'd rather invoke it by using a TagHelper, but it just ain't happening. I've trawled through SO and other helpful pages, and whilst others seem to get it to work, I can't.
I've added the line @addTagHelper "*, AdminConsole"
in _ViewImports.cshtml and <vc:user-details></vc:user-details>
in the view I want to render the VC in, and it does not render; I don't get an error, it just doesn't render.
If I change the TagHelper declaration to @addTagHelper *, AdminConsole
(without the speech marks) it also does not render or error.
If I try both combinations as above and try <vc:UserDetails></vc:UserDetails>
i.e. without the kebab-case, it does not render or error.
My _ViewImports.cshtml
is as follows
@using AdminConsole
@using AdminConsole.Models
@using AdminConsole.Models.AccountViewModels
@using AdminConsole.Models.ManageViewModels
@using Microsoft.AspNetCore.Identity
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration
@addTagHelper "*, AdminConsole"
Using the full namespace for the VC in the @addTagHelper
declaration (AdminConsole.ViewComponents
) produces a cannot resolve TagHelper
error.
I think I've tried all permutations, and documentation from official and community sources only suggest what I've tried (and differ!). I would be very grateful if someone could help shed some light.
@await Component.InvokeAsync("ComponentName")
method? That works for me, but TagHelper is not working. – Juniejunieta