Question

I have defined this bit of code in the <head> section of my _Layout page.

@RenderSection("Styles", false)

Then my index page

@section Styles {
<link rel="stylesheet" type="text/css" href="@Url.Content("~Views/zCSS/ManualProposalWindow.css")" />    
}

My Index page is in Views/Home/Index

My CSS is in Views/CSS/ManualProposalWindow.css

I know the styles are correct because if I put them in a style block inside the index it works fine.

This is the CSS I'm trying to load:

body {
       background: black;
}
Was it helpful?

Solution

Files within the views folder cannot be loaded. They will throw a 404 error due to the httpHandler configured in the Web.config there. This is for security, as you do not want your .cshtml files publicly accessible.

<httpHandlers>
  <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>

Include the css file from any other folder and you should be fine.

OTHER TIPS

Your index page should be like this:

@section Styles
{
    @Styles.Render("~/Content/styleFile.css")
    @Styles.Render("~/Content/orStyleBundle")
}

Also, put your styles in the Content (or similar) folder in your solution.

@section Styles {
            <style>
                .table-striped tbody > tr:nth-child(odd) > td, .table-striped tbody > tr:nth-child(odd) > th {
                    background-color: none;
                }
        
                .table-striped tbody > tr:nth-child(odd) > td, .table-striped tbody > tr:nth-child(odd) > th {
                    background-color: none;
                }
            </style>   
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top