Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

ViewComponent not rendering using TagHelper

$
0
0

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):

namespaceAdminConsole.ViewComponents{[ViewComponent(Name="UserDetails")]publicclassUserDetailsViewComponent:ViewComponent{...does stuff...}

and I can invoke it successfully in a view by using

@awaitComponent.InvokeAsync("UserDetails")

I'd rather invoke it by using a TagHelper, but it just ain't happening. I've trawled through StackOverflow 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

@usingAdminConsole@usingAdminConsole.Models@usingAdminConsole.Models.AccountViewModels@usingAdminConsole.Models.ManageViewModels@usingMicrosoft.AspNetCore.Identity@addTagHelper*,Microsoft.AspNetCore.Mvc.TagHelpers@injectMicrosoft.ApplicationInsights.Extensibility.TelemetryConfigurationTelemetryConfiguration@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.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>