CloudyKooper
CloudyKooper

Reputation: 717

Can I have a HEAD and BODY tag of a view independently from the _Layout.cshtml page?

I have an ASP.NET MVC 3 project with a _Layout.cshtml and the css style sheet being accessed like this:

link href="../../Content/themes/base/jquery.ui.all.css" rel="Stylesheet" type="text/css" 

This is fine for most of the views in my project but there is just one view that I would like to define the style sheet independently and in the view itself. Specifically in the head of the view. This means that the view would have to have it's own head and body tags independently of the _Layout.cshtml file.

Is this possible? If so can someone help me get started with it?

EDIT:

What I'm trying to do is put a style sheet in the head of this one view that would override the CSS from the _Layout.cshtml.

Upvotes: 0

Views: 1294

Answers (1)

Bryan
Bryan

Reputation: 2870

You could define an optional Razor Section in the head tag of your layout. Place it after your main stylesheet, and then it can be used in any views using the layout to bring in additional stylesheets that contain override rules.

_Layout.cshtml

<head>
    <link href="../../Content/themes/base/jquery.ui.all.css" rel="Stylesheet" type="text/css">
    @RenderSection("CssOverrides", false)
</head>

View.cshtml

@section CssOverrides {
    <link href="../../Content/themes/base/jquery.ui.override.css" rel="Stylesheet" type="text/css">
    <!-- additional stylesheets -->
}

Upvotes: 1

Related Questions