获取Styles.Render(),以preserve凹槽从剃刀模板? [英] Getting Styles.Render() to preserve indentation from Razor template?

查看:179
本文介绍了获取Styles.Render(),以preserve凹槽从剃刀模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对可读性的所有标记略有洁癖(因此缩进)。

I'm slightly obsessive about the readability (and hence indentation) of all markup.

当我称之为 @ Styles.Render(〜/内容/ CSS)在ASP.NET MVC4项目,只有第一行缩进保持从我的剃须刀模板。

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

下面是输出:

    <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"/>

我想preFER所有生成的标记有相同的缩进的 @ Styles.Render()电话。

这是很容易做到?如果是这样,怎么样?

Is this easily done? If so, how?

推荐答案

在理想情况下呈现的HTML将精缩。格式化标记是伟大的,同时发展,但使一个更大的文件,如果这是你所服务的用户是什么。

Ideally the rendered HTML would be minified. Formatted markup is great while developing but makes for a bigger file if that is what you are serving to the user.

您看到四个样式表的唯一原因是你在调试环境中,这已停用捆绑运行。正如我在后解释说:<一个href=\"http://stackoverflow.com/questions/14570171/scripts-render-using-outdated-javascript-file/14570455#14570455\">Scripts.Render使用过时的JavaScript文件如果你添加 BundleTable.EnableOptimizations = TRUE; 来的底部,你的 RegisterBundles 在你的 BundleConfig ,它会强制捆绑销售工作(因为它会在释放模式),你会看到这个:

The only reason you see four style sheets is that you are running in a debug environment, which has disabled your bundling. As I explained in the post "Scripts.Render using outdated javascript file" if you add BundleTable.EnableOptimizations = true; to the bottom of your RegisterBundles in your BundleConfig, it will force bundling to work (as it would in release mode), and you'll see that this:

    <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"/>

现在呈现为这样的:

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

所以,是在开发,它不维护您的压痕,但一旦你发布这将是你想要的。

So yes while developing, it isn't maintaining your indentation, but once you publish it will be what you want.

这篇关于获取Styles.Render(),以preserve凹槽从剃刀模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆