user1731254
user1731254

Reputation: 33

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?

Upvotes: 3

Views: 3066

Answers (2)

ScareCrow
ScareCrow

Reputation: 525

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

<partial name="_MenubarPage" />

Upvotes: 1

Andrew Reese
Andrew Reese

Reputation: 912

You can use @RenderPage("_MenubarPage.cshtml");.

You can also use @RenderPage("_MenuPage.cshtml", MyModel) which allows you to supply any model you like to the view by including it as a second parameter.

You can also use @{Html.RenderPartial("_MenubarPage");} if you are using a partial. But don't forget that you need to wrap it with the razor code block @{}

Upvotes: 0

Related Questions