I have a Layout page, which renders a couple of stylesheets with the Style.Render function in MVC4.
However, I want to render some page specific stylesheets on a few views only - what's the best practice to do that? Would you make a new bundle and somehow tell the Layout when to render that?
In your layout, define a section for the additional styles:
<html>
<head>
<!-- other stuff here -->
@RenderSection("CustomStyles", required: false);
</head>
<!-- rest of layout -->
</html>
Then in your view:
@section CustomStyles {
@* custom style content here *@
}
As the section is not required, you can add the view specific styles to only the pages that need it.
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