Difference between RenderBody and RenderSection

Saravana

New Member
In MVC 4/Razor syntax, I'm trying to understand why we need @RenderBody. For example (code taken from http://blog.overridethis.com/blog/post/2010/11/13/Learning-Razor-Shared-Content-Layout.aspx)\[code\]<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>}\[/code\]Why can't I simply use @RenderSection for everything, like this:\[code\]<div id="content"> @RenderSection("Body", required:true)</div>@section Body{ <h1>Body Content</h1>}\[/code\]
 
Back
Top