LoginSignup
9
10

More than 5 years have passed since last update.

ASP.NET MVC5でbootstrap4.0にする

Last updated at Posted at 2018-03-02

やりたいこと

ASP.NET MVC5のプロジェクトテンプレートをbootstrap4.0にアップデートして動かす。
デフォルトはbootstrap3.0が入っている。

作業環境

Visual Studio 2015

作業手順

1.nugetパッケージマネージャーコンソールでbootstrap4.0をインストールします。

PM> Install-Package bootstrap -Version 4.0.0 

参考:https://www.nuget.org/packages/Bootstrap

2.Visual StudioにインストールされているTypeScriptのバージョンが古いとビルドエラーになります。
(おそらく2.1以降でないとダメっぽい。VS2015故デフォルトでインストールされているバージョンが古い…?2017なら大丈夫です。)
 下記から最新のTypeScriptをダウンロードしてインストールします。

3.popper.jsというモジュールが追加されているのでBundleConfig.csに追記します。

BundleConfig.cs
            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/umd/popper.js",
                      "~/Scripts/respond.js"));

このとき、umd配下のものを使用します。
理由は細かく語れるほどの理解度がありませんので省略。。

4.ナビゲーションバーの書式がbootstrap3.0と4.0で違っているので、4.0にあわせて手直しします。
 手直しせずに起動すると、ナビゲーションバーが何も表示されません。

参考:https://getbootstrap.com/docs/4.0/components/navbar/

以上で動くようになりました。

TypeScriptのあたりで意外とハマってしまったのでメモです。

9
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10