Getting .Render () styles to preserve padding from a Razor template?

I am a bit obsessive about the readability (and therefore the indentation) of the entire markup.

When I call @Styles.Render("~/content/css") in an ASP.NET MVC4 project, only the first line supports indentation from my Razor template.

Here is the result:

  <link href="/Content/css/ie.css" rel="stylesheet"/> <link href="/Content/css/1140.css" rel="stylesheet"/> <link href="/Content/css/screen.css" rel="stylesheet"/> <link href="/Content/css/compatibility.css" rel="stylesheet"/> 

I would prefer that all generated markup have the same indentation as the @Styles.Render() call.

Is it easy to do? If so, how?

+4
source share
1 answer

Ideally, the rendered HTML will be reduced. Formatted markup develops well, but makes a larger file if that is what you serve the user.

The only reason you see the four stylesheets is because you are working in a debugging environment that has disabled your package. As I explained in the “ Scripts.Render using an outdated javascript file ,” if you add BundleTable.EnableOptimizations = true; to the bottom of your RegisterBundles in your BundleConfig , this (as in release mode), and you will see that it:

  <link href="/Content/css/ie.css" rel="stylesheet"/> <link href="/Content/css/1140.css" rel="stylesheet"/> <link href="/Content/css/screen.css" rel="stylesheet"/> <link href="/Content/css/compatibility.css" rel="stylesheet"/> 

now displayed as follows:

  <link href="/Content/css?v=Sn3f8Vf56Sr9k0EreIZnouVoGt2cfrd41" rel="stylesheet"/> 

So, yes, while developing, it does not support your indentation, but as soon as you publish it you will want to.

+6
source

All Articles