Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styles.Render in views

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?

like image 504
Peter Schrøder Avatar asked Apr 26 '26 07:04

Peter Schrøder


1 Answers

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.

like image 66
Brendan Green Avatar answered Apr 27 '26 22:04

Brendan Green



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!