[英]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.