dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.4k stars 10k forks source link

In Razor Class Library (RCL) views that use "partial" tag helper won't render nested views when referenced from ASP.NET Razor Pages app #51364

Open haykpetros opened 1 year ago

haykpetros commented 1 year ago

Is there an existing issue for this?

Describe the bug

When referencing Razor Class Library (RCL) Partial View from ASP.NET Razor Pages app, nested views of RCL are not being rendered when using <partial name="..."> tag helper, but will render just fine when using await Html.PartialAsync(...)

Here is the screenshot that shows the behavior of the test solution that is attached to this issue: image

In short, following code:

<h3>This is RCL's Primary Partial rendering nested partial using TagHelper</h3>

@await Html.PartialAsync("_NestedPartial")

and this one:

<h3>This is RCL Primary Partial rendering nested partial using TagHelper</h3>

<partial name="Shared/_NestedPartial.cshtml">

behave differently, when to the best of my understanding they should not. In fact, they behave same way when used directly in Razor Pages web application.

This was tested with .NET 7 and .NET 8 RC2.

WebApplication1.zip

Expected Behavior

According to the documentation (https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/partial-tag-helper?view=aspnetcore-8.0) the Partial Tag Helper <partial> and the HTML Helper options for rendering a partial view @await Html.PartialAsync should behave the same.

Steps To Reproduce

Use attached sample solution to see the behavior.

WebApplication1.zip

Exceptions (if any)

No response

.NET Version

.NET 8 RC2

Anything else?

No response

haykpetros commented 9 months ago

Hi @mkArtakMSFT I am tagging you here hopping you can help to bump this up, as this issue hasn't been updated or commented for a while now, and I am not sure if this is due to me not reporting it properly or maybe something else.

I saw you commenting on something related to RCL as well (Issue #53285), so that is why decided to tag you hopping that you can help in moving this forward.

jeffpapp commented 6 months ago

Hey @haykpetros did you ever get this figured out?

We ran into a similar problem and we needed to add a _ViewImports.cshtml to the RCL project under the Pages folder and add the tag helpers there as well via @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

haykpetros commented 6 months ago

Hey @haykpetros did you ever get this figured out?

We ran into a similar problem and we needed to add a _ViewImports.cshtml to the RCL project under the Pages folder and add the tag helpers there as well via @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Hi @jeffpapp the issue we discovered is that when using await Html.PartialAsync(...) everything works as expected, so if you have <partial name="..."> in your RCL view you will need to replace it with Html.PartialAsync(...). I didn't have time, but planning to test this with latest .NET 9 preview and if this bug is still there report it into .NET 9 branch as advised by @mkArtakMSFT