MVC Razor Syntax – Web forms “Master Page” content area equivalent


In razor instead Web Forms ContentArea’s in Master Pages you have @sections within your _Layout.cshtml file. In the _layout file you have a declaration such as;

@RenderSection("JavaScript", required: false)

Then in your content pages;

@section JavaScript
{
   <script type="text/javascript" src="@Url.Content("/Scripts/SomeScript.js")" />;
   <script type="text/javascript" src="@Url.Content("/Scripts/AnotherScript.js")" />;
}

Source : http://stackoverflow.com/questions/4311783/asp-net-mvc-3-razor-include-js-file-in-head-tag

  1. No comments yet.
(will not be published)