I am new to asp.net mvc platform. I'm developing with razor template engine in mvc 3. I've created a layout page for all view pages but in some cases I need different page headers for different view pages. For example I have to insert additional script elements to page header to validate data in form pages.
I want to know is there any way to add html element to layout page's header from view page?
Thanks in advance.
Right click the Index. cshtml file and select View in Browser. You can also right click the Index. cshtml file and select View in Page Inspector.
You could define a section in the head part of the master page:
<head>
<script type="text/javascript" src="jquery.js"></script>
@RenderSection("scripts")
</head>
and in the view define this section:
@section scripts {
<script type="text/javascript" src="someplugin.js"></script>
}
You also have the possibility to test if a section is defined:
@if (IsSectionDefined("mysection")) {
@RenderSection("mysection")
}
else {
<div>some default content</div>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With