[英]CSS bundling in MVC 4
我正在MVC 4中构建Web应用程序。我正在使用引导程序来设计UI。 我已将引导程序文件包含在解决方案中的BundleConfig.cs文件中,以减小文件大小并优化站点的响应速度和加载速度。 渲染视图页面并引用包名称似乎无法为我输出所需的结果。
我尝试通过CDN引用引导程序,它可以正常工作,所以我认为错误在于捆绑。 但是,我无法找出问题所在。 任何帮助表示赞赏。 谢谢。
BundleConfig.cs
using System.Web;
using System.Web.Optimization;
namespace TMS
{
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.IgnoreList.Clear();
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrapjs").Include(
"~/Scripts/bootstrap.min.js"));
bundles.Add(new StyleBundle("~/Content/BootstrapFiles").Include(
"~/Content/bootstrap.min.css",
"~/Content/bootstrap-responsive.min.css",
"~/Content/bootstrap.css",
"~/Content/bootstrap-responsive.css"));
//BundleTable.EnableOptimizations = true;
}
}
}
_Layout.cshtml
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> -->
@Styles.Render("~/Content/BootstrapFiles")
</head>
在页面的主体中,我试图将导航栏设置为黑色并向右对齐
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Welcome to Sri Lanka!</a>
</div>
<ul id="menu" class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</nav>
PS我还在主web.config文件中将调试模式设置为false
当您的应用程序从全局ajax启动时,您需要调用RegisterBundles
喜欢。
在Global.ajax.cs文件中
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);//for register route
BundleConfig.RegisterBundles(BundleTable.Bundles);//for register bundle
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.