Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why RenderPage is not recognized?

This is discouraging me - I'm using the latest version of .NET core, SDK, visual studio 2019, Started new project - ASP.net core Razor pages, I'm tring to add @RenderPage("") without success.

It looks like it is not part of abstract class RazorPage (that inherit RazorPageBase, at the Microsoft.AspNetCore.Mvc.Razor namespace (part of dotnet\packs\Microsoft.AspNetCore.App.Ref\3.1.3\ref\netcoreapp3.1\Microsoft.AspNetCore.Mvc.Razor.dll))

Everything I try, there is an error that says:

Error CS0103 The name 'RenderPage' does not exist in the current context

my _Layout page looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - TestApp</title>
    @*<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />*@
    <link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
    <div>
        @RenderPage("/Shared/_MenubarPage")
    </div>
    <div class="container">

        
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>

    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>

    @RenderSection("Scripts", required: false)
</body>
</html>

(Of course I have partial _MenubarPage.cshtml page within Shared folder)

Can anyone please tell me where am I doing wrong? Should I add some kind of an external nuget?

like image 681
user1731254 Avatar asked Feb 10 '26 21:02

user1731254


1 Answers

Try the following code snippet in (the asp.net core 3.1) _layout page.

<partial name="_MenubarPage" />
like image 50
ScareCrow Avatar answered Feb 12 '26 15:02

ScareCrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!