1

I have just created a new .net core 3.1 web project and I am able to successfully run it (obviously as one would expect)

enter image description here

but strangely when I add a partial tag helper in my Index.cshtml file to a html file that i know exists:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
    <partial name="~/PrerenderAssets/styles.html" />  @* <--------  this line*@ 
</div>

it renders an exception saying it cannot find it as can be seen in the screenshot below:

enter image description here

This definitely use to work in a .net core 2.1 project I worked on before so after a couple hours researching I cannot seem to find what has changed in .net core 3.1 to cause this issue or is it that I am making a silly mistake somewhere?

you can replicate this issue by creating a new .net core 3.1 web project and creating a folder in the root with a html file it in and trying to render it in the Index.cshtml file.

could someone enlighten me here please? thanks in advance.

Ousmane D.
  • 54,915
  • 8
  • 91
  • 126
  • Does this explain it? https://stackoverflow.com/questions/45526620/asp-net-core-tilde-slash-not-resolving-image-path – Jeroen van Langen Apr 24 '20 at 11:03
  • @JeroenvanLangen I read those answers and understood what they where trying to explain but it doesn't say how it solves this problem at hand. This exact line of code `` works in a .net core 2.1 project. – Ousmane D. Apr 24 '20 at 11:09
  • and using `Url.Content` as suggested in the linked answer results in the same problem. – Ousmane D. Apr 24 '20 at 11:18

1 Answers1

1

file cannot be found in .net core 3.1 with <partial name="~/PrerenderAssets/styles.html" />

work in a .net core 2.1 project

I can reproduce same issue, and it seems that the ViewEngine would reply on build time compiled views (.cshtml files) in 3.0+, which cause the issue.

In your 3.1 project, please use .cshtml file rather than rendering html file as partial view.

<partial name="~/PrerenderAssets/styles.cshtml"/>

Besides, you can refer to this github issue that discussed a similar issue: https://github.com/dotnet/aspnetcore/issues/17650#issuecomment-562671539

Community
  • 1
  • 1
Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • Thanks Fei, your help is very much appreciated!. I spent the entire day on Friday trying to figure out this issue but to no avail. I wish i could vote this answer *a lot more* than just once. – Ousmane D. Apr 26 '20 at 16:42