如何在MVC4中使用捆绑? [英] How do I use bundling in MVC4?
本文介绍了如何在MVC4中使用捆绑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我创建了一个捆绑配置文件,并为其添加了捆绑包。然后我在_Layout.cshtml文件中添加了它的引用。但样式和脚本不起作用。但是当我在html页面中正常添加它时它会起作用。
我在BundleConfig文件中的代码
Hi All,
I have created a bundle config file and added bundles to it. Then I have added its references in _Layout.cshtml file. but the styles and scripts are not working. but it works when I add them normally as in an html page.
My code in BundleConfig file
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/bootstrap.min.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.9.0.js",
"~/Scripts/jquery-1.9.0.min.js",
"~/Scripts/jquery-1.9.0-vsdoc.js",
"~/Scripts/jquery-1.6.4.js",
"~/Scripts/jquery-1.6.4.min.js",
"~/Scripts/jquery-1.6.4-vsdoc.js"
));
bundles.Add(new ScriptBundle("~/bundles/jqueryUI").Include(
"~/Scripts/jquery-ui-1.10.3.custom.min.js",
"~/Scripts/jquery-ui-1.11.1.js",
"~/Scripts/jquery-ui.min-1.11.1.js"
));
bundles.Add(new ScriptBundle("~/bundles/jqueryLibrary").Include(
"~/Scripts/jquery.bxslider.js",
"~/Scripts/jquery.expander.min.js",
"~/Scripts/jquery.jscrollpane.min.js",
"~/Scripts/jquery.kinetic.min.js",
"~/Scripts/jquery.mousewheel.min.js",
"~/Scripts/jquery.parade.js",
"~/Scripts/jquery.prettyPhoto.js",
"~/Scripts/jquery.smoothdivscroll-1.3-min.js",
"~/Scripts/jquery.zweatherfeed.min.js"
));
bundles.Add(new ScriptBundle("~/bundles/scriptLibrary").Include(
"~/Scripts/custom_scripts.js",
"~/Scripts/docs.min.js",
"~/Scripts/google.maps.min.js",
"~/Scripts/ie10 - viewport - bug - workaround.js"
));
bundles.Add(new StyleBundle("~/Content/bootstrap").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap.min.css",
"~/Content/bootstrap-theme.css",
"~/Content/bootstrap-theme.min.css"));
bundles.Add(new StyleBundle("~/Content/font-awesome").Include(
"~/Content/font-awesome.css",
"~/Content/font-awesome.min.css"));
bundles.Add(new StyleBundle("~/Content/jqueryui").Include(
"~/Content/jquery/jquery-ui-1.8.16.custom.css"));
bundles.Add(new StyleBundle("~/Content/library").Include(
"~/Content/jquery.bxslider.css",
"~/Content/prettyPhoto.css",
"~/Content/parade_smooth.css",
"~/Content/zweatherfeed.css",
"~/Content/custom.css"
));
}
_Layout.cshtml中的代码
Code in _Layout.cshtml
@Styles.Render("~/Content/bootstrap")
@Styles.Render("~/Content/font-awesome")
@Styles.Render("~/Content/library")
@Styles.Render("~/Content/jqueryui")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryUI")
@Scripts.Render("~/bundles/jqueryLibrary")
@Scripts.Render("~/bundles/scriptLibrary")
任何人请帮帮我..
Any one help me please..
推荐答案
请访问以下链接:
http://www.deliveron.com/blog/post/Be-Careful-When-Bundling-Stylesheets-in-MVC-4.aspx [ ^ ]
如果您使用的是Visual Studio 2010 ..可能上面的链接可能会解决您的问题。
如有任何疑问,请发布您的查询。 />
谢谢。
Please visit below link:
http://www.deliveron.com/blog/post/Be-Careful-When-Bundling-Stylesheets-in-MVC-4.aspx[^]
If you are using Visual Studio 2010..it is possible above link may fix your issue.
In case of any difficulty please post your query.
Thanks.
大家好,
我得到了答案。这是因为没有在Global.asax.cs文件中注册bundle。
Hi all,
I got the answer atlast. It was due to not registering the bundles in the Global.asax.cs file.
BundleConfig.RegisterBundles(BundleTable.Bundles);
谢谢大家的支持..
any way thank you all for you support..
附加参考。
ASP.NET MVC捆绑内部 [ ^ ]
这篇关于如何在MVC4中使用捆绑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文