Skip to main content

The equivalent of content placeholders in ASP.NET Razor (MVC) are called sections.

<!-- In your _Layout.cshtml: -->

<head>
@RenderSection("Styles", required: false)
</head>

<!-- Then in your content page: -->

@section Styles {
    <link href="@Url.Content("~/Content/StandardSize.css")" />
}

<!-- An alternative solution would be to put your styles into ViewBag/ViewData: -->

<!-- In your _Layout.cshtml: -->

<head>
    @foreach(string style in ViewBag.Styles ?? new string[0]) {
        <link href="@Url.Content(style)" />
    }
</head>

<!-- And in your content page: -->

@{
    ViewBag.Styles = new[] { "~/Content/StandardSize.css" };
}

<!-- This works because the view page gets executed before the layout. -->