In the main section of the main page (for example, _Layout.cshtml) add a call to RenderSection. The header section may look like this:
<head> <meta charset="utf-8" /> <meta name="description" content="The content description" /> <link rel="shortcut icon" href="@Url.Content("~/Content/images/favicon.ico")" /> <title>@ViewBag.Title</title> @RenderSection("css", false) </head>
Then in your index.cshtml use the section to add the css link:
@section css { <link href="@Url.Content("~/css/style.css")" rel="stylesheet"/> }
Please note that "css" is a unique name for your section, and it must match. You can also use this section in any view you want. The part you specify in the css section will be displayed in the header of your html, only where you place the placeholder RenderSection in your _Layout.cshtml.
source share