Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David 20 posts 131 karma points
    Dec 04, 2018 @ 19:28
    David
    0

    Cannot be requested directly because it calls the "RenderBody" method.

    I am new to C# but even newer to Umbraco. Sadly, I have hit a bit of a wall and can't work out why I receive the following error: The file "~/Views/Master.cshtml" cannot be requested directly because it calls the "RenderBody" method. I understand what it is saying (I think). You can't directly reference RenderBody() within a Template, RenderBody() and its content is merged in with the Template as and when it is requested. This article (on this site), and this one (on S.O) taught me that.

    This is my tree structure

    Doc type and Template with a Standard Page inherit from Master Template

    'Master' is my 'base'' layout page with my HTML, Styles.Render, Scripts.Render etc which will form my main page Template. 'Standard Page' was created to point at that Layout page, and to place its content inside the RenderBody() called within 'Master'. My 'PageBase' Document Type for now just contains a text field with one input for 'Meta Description' which will show across all pages.

    I did wonder whether I had set my Permissions and Templates right for my Document Types, but it does look like it.

    Template selection for Standard Page Document Type

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<PageBase>
    @{
    Layout = null;
    }
    @using System.Web.Optimization
    <!DOCTYPE html>
    <html class="app no-js" lang="en" dir="ltr">
    <head>
    <base href="/">
    <title>Hugh</title>
    <meta name="description" content="@Model.Content.MetaDescription" />
    @Styles.Render("~/build/styles")
    </head>
    <body>
       <main>
           @RenderBody()
       </main>
    @Scripts.Render("~/build/scripts")
    @RenderSection("scripts", required: false)
    </body>
    </html>
    

    My very simple 'Standard Page' Template looks like this:

    @inherits UmbracoTemplatePage<StandardPage>
    @{
        Layout = "Master.cshtml";
    }
    
    <h1>@Model.Content.PageTitle</h1>
    

    When I run the application this is my error:

    Server error

    I am so grateful for some guidance - thank you! :-)

    -David

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 05, 2018 @ 20:56
    Jan Skovgaard
    100

    Hello David and welcome to Our :-)

    If I understand things correctly then I think the issue is that you have selected the "Master" template on your "Standard page" document type.

    You should select the "Standard page" template for it instead and then things should be working.

    I hope this makes sense and that I understood your issue correctly.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft