我有一个布局页面(Layout page),通过MVC4的Style.Render函数渲染了一些样式表。
然而,我想在仅限于某些视图的情况下渲染一些特定于页面的样式表 - 最佳实践是什么?您会创建一个新的bundle并告诉Layout何时进行渲染吗?
我有一个布局页面(Layout page),通过MVC4的Style.Render函数渲染了一些样式表。
然而,我想在仅限于某些视图的情况下渲染一些特定于页面的样式表 - 最佳实践是什么?您会创建一个新的bundle并告诉Layout何时进行渲染吗?
<html>
<head>
<!-- other stuff here -->
@RenderSection("CustomStyles", required: false);
</head>
<!-- rest of layout -->
</html>
@section CustomStyles {
@* custom style content here *@
}
由于该部分不是必需的,因此您可以将视图特定样式添加到仅需要它的页面中。
你可以使用@RenderSection("yourCustomSection")
来实现这一点。如果不是必需的,那么你可以可选地进行操作。
@RenderSection("MyCustomStyleSection",false)
@section
。