Difference between RenderBody and RenderSection

asp.net, asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4, asp.net-mvc-5

Solution

Simply because of convenience. Rendering the body is something that you would most likely do so its good to have a dedicated function for that. Keeps you from declaring a @section for the body and gives an easier to call function.

Problem

In MVC/Razor syntax, I'm trying to understand why we need `@RenderBody`. For example (code taken from example) ``` <html> <head> <meta charset="utf-8" /> <title>My WebSite</title> <style> #container { width: 700px; } #left { float: left; width: 150px; } #content { padding: 0 210px 0 160px; } #right { float: right; width: 200px; } .clear { clear: both; } </style> </head> <body> <div id="container"> <div id="left"> @RenderSection("left", required:false) </div> <div id="content"> @RenderBody() </div> <div id="right"> @RenderSection("right", required:false) </div> <div class="clear"></div> </div> </body> </html> @{ Layout = "~/_3ColLayout.cshtml"; } <h1>Main Content</h1> @section left { <h1>Left Content</h1> } @section right { <h1>Right Content</h1> } ``` Why can't I simply use `@RenderSection` for everything, like this: ``` <div id="content"> @RenderSection("Body", required:true) </div> @section Body{ <h1>Body Content</h1> } ```

Original source