Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Oct 08, 2016 @ 16:09

    The file "~/Views/Master.cshtml" cannot be requested directly because it calls the "RenderBody" method.

    I don't really understand this error and I am having a rough time. I want to use RenderBody() method to load subpages like contact, about, etc, upon being clicked in the navigation bar.

    Another note: I do not understand the reason why I cannot add @model to my master page, why can't I do that but have to create two extra partial pages when creating a contact form.

    enter image description here enter image description here enter image description here

    Thank you!

  • Dennis Flæng Jørgensen 35 posts 145 karma points c-trib
    Oct 08, 2016 @ 17:53
    Dennis Flæng Jørgensen
    1

    In MVC, whenever a view has a RenderBody-method it's a template view. Template views can't be request/presented by itself. It needs a subview to be rendered (where you wrote "RenderBody()") to make up a valid page.

    If you want to display only the template view, you need to make a empty subview that uses this template view as its layout. This subview cannot be a template view (call a RenderBody-method) itself.

    For more: http://stackoverflow.com/questions/17368464/trying-to-use-two-layout-pages-on-mvc4-and-razor

    On your second note: I belive you can reference your model in UmbracoTemplatePage. Try moving line #2 (the @using-line) above the @inherits-line and see if that doesn't fix your problem - the variable of "ContentModels" is unknown to line #1 because it isn't defined untill line #2 :)

  • Comment author was deleted

    Oct 08, 2016 @ 19:00

    Hey Dennis I feel like I understand what you are saying but I am still receiving this error.

    Here is an index.html that I was to be replaced (loaded into) RenderBody(); in my Master.cshtml which is my template/layout. enter image description here This is my index.cshtml which inherits to layout Master.cshtml which is my template (layout page). I entered "RenderBody()" strictly into the Master.cshtml with the goal of having Index.cshtml being load into it by default.

    And I am still receiving this error. I do not want two layouts, just one which will be Master.cshtml. Thank you!

  • Comment author was deleted

    Oct 08, 2016 @ 19:09

    Hey actually I think the best thing to do right now would be to watch the umbraco.tv episodes.

  • Eduard 1 post 71 karma points
    Nov 10, 2016 @ 14:03
    Eduard
    0

    Hi Everyone,

    I receive the following error . "cannot be requested directly because it calls the "RenderBody()" method" and the same for RenderSection(). Can anyone help me ?

    Thanks, Eduard

  • Dennis Flæng Jørgensen 35 posts 145 karma points c-trib
    Nov 10, 2016 @ 16:36
    Dennis Flæng Jørgensen
    0

    Hey Eduard

    Did you read my answer to OP?

    If there's something I need explaining again please ask (I know I might not have explained it very well).

    But the way around this problem is basically to either remove the "RenderBody()" or call the template that inherits from the layout you're trying to call - since you cannot call that page directly.

  • Chris Clancy 63 posts 132 karma points
    Nov 11, 2016 @ 09:04
    Chris Clancy
    0

    Hi Maciej,

    Is your doc type using the master template to render your page?

Please Sign in or register to post replies

Write your reply to:

Draft