我正在尝试使用MVC4的新功能"捆绑和缩小文件"。
对于IE条件注释,我仍然沿用旧方式:<!--[if lt IE 9]><link href=.../><![endif]-->
或者 <!--[if lt IE 9]>@Styles.Render("~/foo")<![endif]-->
,但似乎无法自动处理调试/发布。
是否存在内置方法来处理这个问题?其他人是如何做到的?
编辑:
同时,在渲染输出中包含<noscript>
标签将非常有用(用于回退)。
我正在尝试使用MVC4的新功能"捆绑和缩小文件"。
对于IE条件注释,我仍然沿用旧方式:<!--[if lt IE 9]><link href=.../><![endif]-->
或者 <!--[if lt IE 9]>@Styles.Render("~/foo")<![endif]-->
,但似乎无法自动处理调试/发布。
是否存在内置方法来处理这个问题?其他人是如何做到的?
编辑:
同时,在渲染输出中包含<noscript>
标签将非常有用(用于回退)。
在我找到更好的方法之前,我创建了一个适配器类名为Bundles
,它有一个方法:
public static IHtmlString RenderStylesIe(string ie, params string[] paths) {
var tag = string.Format("<!--[if {0}]>{1}<![endif]-->", ie, Styles.Render(paths));
return new MvcHtmlString(tag);
}
对于脚本,也有类似的方法。视图可以像这样调用它们:
@Bundles.RenderStylesIe("lt IE 9", "~/Content/foo")
@Bundles.RenderScriptsIe("lte IE 7", "~/Scripts/bar")
如果有更好的方法,我会欣赏建议。
我发现的另一种选择在这里:https://coderwall.com/p/5zqvkg
这是一个偏好问题。
(仍然喜欢上面的代码-它更清晰,更易读)
@Bundles.RenderStylesIe("lt IE 9", "~/Content/foo")
@Bundles.RenderScriptsIe("lte IE 7", "~/Scripts/bar")
)
<noscript>
标签,通常用于CSS回退。 - Bobby B