Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 18, 2011 12:27 PM by KSighem
Member
15 Points
5 Posts
Jul 18, 2011 11:55 AM|LINK
I'm trying to get my first MVC Razor app to work, and I not having much luck with it.
Using the sample code from some blog I try to get a section rendered like so:
<!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script> </head> <body> @section top{<h1>Test</h1>} <div class="page"> <div id="header"> @RenderSection("top") </div> <div id="main"> @RenderBody() </div> </div> </body> </html>
I varied the location of @section bit, but I keep getting the
error. What am I missing?
All-Star
24675 Points
4250 Posts
Jul 18, 2011 12:10 PM|LINK
You define the section in a view and render it in the _Layout.cshtml (aka the master page).
Check this for more info:
http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx
Jul 18, 2011 12:27 PM|LINK
I understand the section has to be on all views serviced by _Layout. Thanks
KSighem
Member
15 Points
5 Posts
MVC 3 Razor Render Section
Jul 18, 2011 11:55 AM|LINK
<!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script> </head> <body> @section top{<h1>Test</h1>} <div class="page"> <div id="header"> @RenderSection("top") </div> <div id="main"> @RenderBody() </div> </div> </body> </html>Section not defined: "top".
raduenuca
All-Star
24675 Points
4250 Posts
Re: MVC 3 Razor Render Section
Jul 18, 2011 12:10 PM|LINK
You define the section in a view and render it in the _Layout.cshtml (aka the master page).
Check this for more info:
http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx
Radu Enuca | Blog
KSighem
Member
15 Points
5 Posts
Re: MVC 3 Razor Render Section
Jul 18, 2011 12:27 PM|LINK
I understand the section has to be on all views serviced by _Layout. Thanks