Copied to clipboard

Flag this post as spam?

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


  • Mathias Poulsen 18 posts 139 karma points
    Apr 12, 2013 @ 23:11
    Mathias Poulsen
    0

    Exception when i use the methods RenderBody() and RenderSection()

    Hello,

    When i use the methods @RenderBody() and @RenderSection() on my main view, it throws an exception saying that my view (and because of that, my page) cannot be requested directly because it calls the RenderBody method.

    Now i have read through the get started tutorial and plenty of other documentation to get started on Umbraco MVC, but it seems like noone in this community is experiencing the same behavior.. Maybe you can help me point out what i am doing wrong? This is my markup:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
      Layout = null;
    }
    
    <!doctype html>
    <html>
    <head>
      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>@Model.Content.Name | Mogens Kromann</title>
      <link rel="stylesheet" href="/css/vendor/bootstrap.min.css"/>
    </head>
      <body>
    
        <div class="navbar navbar-inverse navbar-fixed-top">
          <div class="navbar-inner">
            <div class="container-fluid nav-collapse">
              <a class="brand" href="/">Mogens Kromann</a>
              @Umbraco.RenderMacro("Navigation")
            </div>
          </div>
        </div>
    
        <div class="container">
          @RenderBody()
        </div>
    
        <script src="/scripts/vendor/jquery.min.js"></script>
        <script src="/scripts/vendor/bootstrap.min.js"></script>
    
      </body>
    </html>

    Edit, here is my exception:

    Server Error in '/' Application.

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

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The file "~/Views/Main.cshtml" cannot be requested directly because it calls the "RenderBody" method.

    Source Error:

    Line 25:     
    Line 26:     
    Line 27: @RenderBody() Line 28:
    Line 29:

    Source File: c:\Users\mp\Desktop\MogensKromann\Website\views\Main.cshtml    Line: 27

    Let me know if you need the stacktrace..

    Regards and thanks in advance,

    Mathias.

  • Mathias Poulsen 18 posts 139 karma points
    Apr 12, 2013 @ 23:26
    Mathias Poulsen
    101

    It seems like i lost all my braincells during the Umbraco Festival today, i found the answer.
    In future reference if there is other people out there experiencing the same thing, you need to create a subtemplate to your main template, so you dont call your main template directly, exactly as it says, doh!

  • Andrew 1 post 21 karma points
    Aug 03, 2013 @ 18:38
    Andrew
    0

    Am really pleased you posted this.  Would have probabley take a long time to realize my mistake if you hadn't and I don't have the excuse of the Umbraco festival to fall back on.

  • Ravindra 46 posts 117 karma points
    Jul 29, 2014 @ 09:49
    Ravindra
    0

    Can u make it clear! i have tried as u said but no use!

    Ravindra!

     

  • Jan Egil Kristiansen 37 posts 160 karma points
    Nov 15, 2016 @ 10:49
    Jan Egil Kristiansen
    0

    But does the throwing of an exception make sense?

    When I call my master template directly, I would expect @RenderBody() to render an empty string.

    I find that I can catch the exception myself in the master template. Still, I feel like replacing the exception with an empty string, is something that belongs inside of @RenderBody.

Please Sign in or register to post replies

Write your reply to:

Draft