In a .NET MVC4
project how does @Styles.Render
works?
I mean, in @Styles.Render("~/Content/css")
which file is it calling?
I dont have a file or a folder called "css" inside my Content
folder.
In a .NET MVC4
project how does @Styles.Render
works?
I mean, in @Styles.Render("~/Content/css")
which file is it calling?
I dont have a file or a folder called "css" inside my Content
folder.
Polo I wouldn't use Bundles in MVC for multiple reasons. It doesn't work in your case because you have to set up a custom BundleConfig class in your Apps_Start folder. This makes no sense when you can simple add a style in the head of your html like so:
You can also add these to a Layout.cshtml or partial class that's called from all your views and dropped into each page. If your styles change, you can easily change the name and path without having to recompile.
Adding hard-coded links to CSS in a class breaks with the whole purpose of separation of the UI and design from the application model, as well. You also don't want hard coded style sheet paths managed in c# because you can no longer build "skins" or separate style models for say different devices, themes, etc. like so:
Using this system and Razor you can now switch out the Skin Path from a database or user setting and change the whole design of your website by just changing the path dynamically.
The whole purpose of CSS 15 years ago was to develop both user-controlled and application-controlled style sheet "skins" for sites so you could switch out the UI look and feel separate from the application and repurpose the content independent of the data structure.....for example a printable version, mobile, audio version, raw xml, etc.
By moving back now to this "old-fashioned", hard-coded path system using C# classes, rigid styles like Bootstrap, and merging the themes of sites with application code, we have gone backwards again to how websites were built in 1998.
Watch out for case sensitivity. If you have a file
and you redirect in your Bundle.config to
it will not load the css.
It's calling the files included in that particular bundle which is declared inside the
BundleConfig
class in theApp_Start
folder.In that particular case The call to
@Styles.Render("~/Content/css")
is calling "~/Content/site.css".A bit late to the party. But it seems like no one has mentioned
bundling & minification of
StyleBundle
, so..calls in
Application_Start()
:which in turn calls
RegisterBundles()
effectively combines & minifiesbootstrap.css
&Site.css
into a single file,
But..
only when
debug
is set tofalse
inWeb.config
.Otherwise
bootstrap.css
&Site.css
will be served individually.Not bundled, nor minified:
As defined in App_start.BundleConfig, it's just calling
Nothing happens even if you remove that section.
I did all things necessary to add bundling to an MVC 3 web (I'm new to the existing solution).
Styles.Render
didn't work for me. I finally discovered I was simply missing a colon. In a master page:<%: Styles.Render("~/Content/Css") %>
I'm still confused about why (on the same page)<% Html.RenderPartial("LogOnUserControl"); %>
works without the colon.