Robertcode :
I have an MVC View that uses a layout page which has all the settings to display the site menu and other things. In this particular view, I would like to add a style to the body style it has inherited from the layout page without modifying the layout page?. Is there a way to add a style to the body of a view page that is already using a layout page? For example, on this one particular page I'd like to add the following style to what it is already using for the body:
background: linear-gradient(174deg, rgba(2,0,36,1) 0%, rgba(33,48,153,0.7130128662793243) 63%, rgba(49,0,255,1) 100%);
Thanks in advance.
bmartins :
What you're looking for is called Section.
You can define a section in your _Layout.cshtml
:
<!-- _Layout.cshtml -->
@RenderSection("Styles", required: false)
And then, fill it in your child view :
<!-- ChildView.cshtml -->
@section Styles {
<style>
/* your stylesheet */
</style>
}
I hope this helps you.