6

I am using MVC4 and have added Bootstrap and Font Awesome via nuget.

I can see how Bootstrap gets bundled in via BootstrapBundleConfig.cs (which was added by the nuget package) below:

public static void RegisterBundles()
{
    BundleTable.Bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap*"));
    BundleTable.Bundles.Add(new StyleBundle("~/Content/bootstrap").Include("~/Content/bootstrap.css", "~/Content/bootstrap-responsive.css"));
}

I have the following questions:

  1. For font-awesome, I don't see similar bundling code to the above for registering the required css files, is there any, or do i just link to the stylesheet in the content directory <link href="~/Content/font-awesome.min.css" rel="stylesheet" /> - what is the proper way?
  2. For bootstrap, if I do not want a responsive layout, would I just comment out the bootstrap-responsive.css from Include("~/Content/bootstrap.css", "~/Content/bootstrap-responsive.css"))?
4

1 回答 1

10

您可以在asp.net站点上阅读有关捆绑如何工作的更多信息。

BootStrap nuget 包似乎为您制作了一些捆绑包。您可以修改它以在现有捆绑包中包含 Font Awesome,或使其成为自己的捆绑包

例如

public static void RegisterBundles()
{
    BundleTable.Bundles
        .Add(new ScriptBundle("~/bundles/bootstrap")
        .Include("~/Scripts/bootstrap*"));

    // Either add it to the  existing bundle
    BundleTable.Bundles
        .Add(new StyleBundle("~/Content/bootstrap")
        .Include("~/Content/bootstrap.css", 
                "~/Content/bootstrap-responsive.css",
                "~/Content/font-awesome.css"));

    // Or make it it's own bundle
    BundleTable.Bundles
        .Add(new StyleBundle("~/Content/font-awesome")
        .Include("~/Content/font-awesome.css"));

}

然后,您需要确保您_layout.cshtml渲染了这些捆绑包(Bootstrap nuget 可能没有为您完成此操作)。

例如

@Styles.Render("~/Content/bootstrap")

// Or, if you made it it's own bundle
@Styles.Render("~/Content/font-awesome")

如果您不想在包中包含 ~/Content/bootstrap-responsive.css,只需从Include方法中删除此字符串即可。

于 2013-06-28T01:41:32.863 回答