asp.net mvc - Html.Partial and @section MVC -
what's difference between @html.partial, @html.section , @section ? when should use each of them?
@html.partial split page parts. page incomplete without filling in part.
@html.section (often optional) portion, defined in layouts, inheritors can add content into. example, if want add scripts page, there's "scripts" section @ end of default layout allows pages inject @ end of content.
@section defining content @html.section in child page.
for example:
<!-- layout page. --> <!doctype html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> </head> <body> <div class="container body-content"> layout content.<br/> @renderbody() </div> @rendersection("scripts", required: false) </body> </html> ...
<!-- child page --> @section scripts{ <script src="/scripts/jquery.signalr-2.2.1.min.js"></script> } <div>child content.</div> <div>partial content here: @html.partial("~/views/partialcontent.cshtml")</div> ...
<!-- partial content in partialcontent.cshtml --> hello! the result like:
layout content. child content. partial content here: hello!
Comments
Post a Comment