C#C
C#15mo ago
Roofboy

Partial view not found in Razor Pages despite being in the correct location

I am looking to import a few partials into a page within the _Layout file.

The _Layout file contains the following code:

<!doctype html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PicShare</title>
    <link rel="stylesheet" href="~/css/app.css">
</head>
<body>

    @await Html.PartialAsync("_TopHeader");

    @await Html.PartialAsync("_NewPost")

    @RenderBody()

    <script src="~/js/app.js"></script>
    <script src="~/js/index.js"></script>
</body>
</html>

_TopHeader is rendered completely fine despite being in the same folder and location as _NewPost. They both have the same file extention however _NewPost cannot be found.

The error message thrown is:
An unhandled exception occurred while processing the request.
InvalidOperationException: The partial view '_NewPost' was not found. The following locations were searched:
/Pages/_NewPost.cshtml
/Pages/Shared/_NewPost.cshtml
/Views/Shared/_NewPost.cshtml


I have also attached the file structure.
image.png
Was this page helpful?