Closed mmillican closed 7 years ago
What happens if you put your @addTagHelper ...
directly in the view in question?
@rynowak That seems to work. So it seems like it doesn't "inherit" the _ViewImports
then if its an embedded view?
That's what it's looking like. There's some shenanigans that can take place with the embedded view approach. Is there a _ViewImports.cshtml
in your Views
folder that's getting embedded along with the views?
Yup. I did notice that I had to explicitly set the _Layout
for each of the views also (instead of using the _ViewStart
so I guess this sort of makes sense, but is kind of a bummer.
FWIW also, the public project ("destination" that the embedded views are being added to) also have the same lines in the _ViewImports
but it doesn't seem to look at that.
/cc @pranavkm - what's the best advice here?
Let me have a look - I'd expect it to work at runtime, but maybe there's some quirky behavior of the embedded file provider that's affecting this.
@mmillican - do you have a sample application available that demonstrates this issue? I tried out several combinations of app with embedded views \ app referencing a class library with embedded views using both built-in and custom tag helpers and I could not reproduce what you're seeing here.
@pranavkm it's unfortunately not OSS, but I will try to reproduce it in a separate project later today to see the results. Otherwise do you have your sample that I could maybe compare against (mainly configuration and project files)? Thanks for looking into it.
Here you go - https://github.com/pranavkm/embedded-views-classslib.
Note: I'm using our dev bits just because that what's I had handy on my machine, but this should just work going back to 1.0.
@mmillican feel free to re-open this once you've had a chance to determine what the cause of your issue is. I have my sample app available here (https://github.com/pranavkm/embedded-views-classslib) as reference.
@pranavkm From what I can see, aside from some project structure items, there's no major differences. I'll try to re-create from the ground up tonight and see what I come up with. Thanks for the guidance on this!
TL;DR:
A simple
TagHelper
component (it has been slimmed down to troubleshoot this issue) works included on a "normal" view in an MVC; when it's in an embedded view, I just see the<admin-assets location="Header"></admin-assets>
being rendered in source.I am building an application which has a few different parts to it: a shared library (class lib), a "public" MVC project and an "admin" MVC project. The admin project can run on its own, but it is designed to be referenced by the public project.
The views in the admin project are all embedded resources (via
<EmbeddedResource Include="Views\**" Exclude="bin\**;obj\**;packages\**;@(EmbeddedResource)" />
in the `.csproj).If the tag helper is included in a view in the public project, it renders as I would expect, however when in a view that's coming from the admin project, it does not. The embedded views render fine otherwise.