How to insert additional content into the page title from the watch page?

I am new to asp.net mvc platform. I am developing using the razor template mechanism in mvc 3. I created a layout page for all the viewing pages, but in some cases I need different page headers for different viewing pages. For example, I have to insert additional script elements in the page header to check the data on the form pages.

I want to know if there is a way to add an html element to the header of the layout page from the view page?

Thanks in advance.

+5
source share
1 answer

You can define a section in the main part of the main 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>
}

, :

@if (IsSectionDefined("mysection")) { 
    @RenderSection("mysection")
} 
else {
    <div>some default content</div>
}
+11

All Articles