- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- dotNet-ASP.NET MVC/Razor/CSS・JSファイルのインクルード へ行く。
- 1 (2014-02-10 (月) 17:50:07)
Razor - CSS・JSファイルのインクルード
CSS/JSファイルパスをBudleに指定
App_Start\BudnleConfig.cs
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
レイアウトファイルでBundleを呼び出す
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - マイ ASP.NET アプリケーション</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
参考
http://stackoverflow.com/questions/12028401/styles-render-in-mvc4