3

Possible Duplicate:
How to reference a .css file on a razor view?

How to add page specfic css in asp.net mvc3 views but i dont want to add

css for page in header , is there any other solution ???

Community
  • 1
  • 1
smart boy
  • 671
  • 4
  • 11
  • 24
  • Use a `@section` - see [here](http://stackoverflow.com/questions/5021552/how-to-reference-a-css-file-on-a-razor-view) – StuartLC Oct 11 '12 at 09:48

2 Answers2

8

You could define a section in your _Layout.cshtml:

<head>
    ...
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    @RenderSection("styles", false)
    ...
</head>

and then inside your view override this section to include the specific CSS for the given view:

@section styles {
    <link href="@Url.Content("~/Content/index.css")" rel="stylesheet" type="text/css" />
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

using jquery you can do it.

var cssselection;
if(x)
  cssselection=default.css
 else
   cssselection=first.css

$(function() {
   $('link').first().attr('href', cssselection);
});
amesh
  • 1,311
  • 3
  • 21
  • 51