How to add head section in a page that has layout template


Tags: css,asp.net,asp.net-mvc,asp.net-mvc-4

Problem :

I need add specific css file for my page "Index.cshtml" that has layout "_BasicLayout.cshtml".

In ASP.NET WebForms I could do it with ContentPlaceHolder like this:

Master Page:

<head>
    <Link rel="stylesheet" type="text/css" href="common.css" />
    <ContentPlaceHolder ID="Head" />
</head>

Child Page (Layout = Master Page):

<asp:Content ContentPlaceHolderID="Head">
     <Link rel="stylesheet" type="text/css" href="specific.css" />
</asp:Content>

Question:

How to do it in ASP.NET MVC?



Solution :

In your Layout page put something like this:

@RenderSection("AdditionalStyles", required: false)

Then in your child pages where you want to use it, you can do:

@section AdditionalStyles
{
    @Styles.Render("~/Content/fileupload/css")
}

    CSS Howto..

    How to make text appear at the top left corner?

    Does anybody know how I can adjust this CSS to achieve the desired hyperlink effect I'd like?

    How to create responsive blocks by using just CSS and HTML

    Wordpress- How do i change the default font of navigation menu?

    How to center two blocks with some gap inbetween using CSS?

    How to get width of
  • stretched to available space in parent
      in IE7?
  • How do I resize an image in IE 8

    How to change extjs grid single cell background color depending on value changes?

    Displaying a title and description on a jquery slideshow

    How to target CSS module classes after they are hashed?

    How to use easeOutBounce animiation on display block?

    How to change the style of an active menu with php + css

    how to increase/decrease font-size from external css [closed]

    How do I get a td background color to stretch from left to right, not just the table width, in html & css?

    How can I get li items to slide and/or fade into view on this jQuery list?

    How to change css for an element but keep defaults for it's children

    HTML, CSS. Show the second node first before the first node in MOBILE site

    Best practice: how to name css default state? [closed]

    How to remove div backgrounds?

    How to display thumbnail in dropdown CSS list along with other styling of text

    CSS: How to float:right and center

    How do I suppress errors in IntelliJ Idea 12

    how to achieve following using css ( digits input )

    jquery .show() hides immediately

    How to make the footer stick to the bottom?

    How to draw a border around a semitransparent image? (css) [duplicate]

    jQuery .animate() sets display:none, how to avoid?

    how do I center this image, without touching the HTML

    How to make section be tall enough to store data (fullpage.js)?

    How to add CSS for specific pages in RefineryCMS?