MVC4中的Bootstrap和font-awesome

g18*_*18c 6 asp.net-mvc-4 twitter-bootstrap font-awesome

我正在使用MVC4并通过nuget添加了Bootstrap和Font Awesome.

我可以看到Bootstrap如何捆绑在via BootstrapBundleConfig.cs(由nuget包添加)下面:

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"));
}
Run Code Online (Sandbox Code Playgroud)

我有以下问题:

  1. 对于font-awesome,我没有看到上面类似的捆绑代码用于注册所需的css文件,有没有,或者我只是链接到内容目录中的样式表<link href="~/Content/font-awesome.min.css" rel="stylesheet" />- 正确的方法是什么?
  2. 对于bootstrap,如果我不想要响应式布局,我是否只会注释掉bootstrap-responsive.css Include("~/Content/bootstrap.css", "~/Content/bootstrap-responsive.css"))

Sta*_*anK 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"));

}
Run Code Online (Sandbox Code Playgroud)

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

例如

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

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

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