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を呼び出す

Views\Shared\_Layout.cshtml

 <!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


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2014-02-10 (月) 17:51:12