vb.net 如何将自定义 css 文件添加到 asp.net mvc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23159218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add custom css files to asp.net mvc?
提问by Er Mayank
How to add css files in asp.net mvc4 project. I have 3 css files like this
如何在asp.net mvc4 项目中添加css文件。我有 3 个这样的 css 文件
images/img.css
content/con.css
styles.css
i added in bundleconfig.vb but its not working.
我在 bundleconfig.vb 中添加但它不工作。
bundles.Add(New StyleBundle("~/Content/css").Include("~/images/img.css"))
bundles.Add(New StyleBundle("~/Content/css").Include("~/content/con.css"))
bundles.Add(New StyleBundle("~/Content/css").Include("~/styles.css"))
In view page
在查看页面
<%: Styles.Render("~/Content/css") %>
<%: Scripts.Render("~/bundles/modernizr") %>
回答by
Try this :
尝试这个 :
bundles.Add(New StyleBundle("~/AllStyles").IncludeDirectory("~/images","img.css")_
.IncludeDirectory("~/content","con.css")_
.Include("~/styles.css"))
In your view Page:
在您的视图页面中:
<%: Styles.Render("~/AllStyles") %>
or
或者
bundles.Add(New StyleBundle("~/bundles/img").Include("~/images/img.css"))
bundles.Add(New StyleBundle("~/bundles/content").Include("~/content/con.css"))
bundles.Add(New StyleBundle("~/bundles/style").Include("~/styles.css"))
In your view Page:
在您的视图页面中:
<%: Styles.Render("~/bundles/img","~/bundles/content","~/bundles/style") %>
And remind that you must add in the Global.asax.vb file this BundleConfig.RegisterBundles(BundleTable.Bundles);
并提醒您必须在 Global.asax.vb 文件中添加此 BundleConfig.RegisterBundles(BundleTable.Bundles);
回答by tweray
Correct way to include multiple css/js into a single bundle:
将多个 css/js 包含到单个包中的正确方法:
bundles.Add(New StyleBundle("~/Content/css").Include(
"~/images/img.css",
"~/content/con.css",
"~/styles.css"))
What your origin code did is registering 3 bundles overwriting each other and after all only 1 css get included.
您的原始代码所做的是注册 3 个相互覆盖的包,毕竟只有 1 个 css 被包含在内。
回答by Jason Roell
Yes, you must register the bundles in your application.
是的,您必须在您的应用程序中注册这些包。
(this is for c# but very similar code to vb)
(这是针对 c# 但与 vb 非常相似的代码)
Global.asax.cs :
Global.asax.cs :
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// Register the bundles
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
BundleConfig.cs :
BundleConfig.cs :
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~bundles/someCss").Include(
"~/css/myothercssfile.css*",
"~/css/mycss.css*"
));
}
And this code in your view :
在您看来,这段代码是:
<%: Styles.Render("~/bundles/someCss") %>

