加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – MVC4中的Bootstrap和font-awesome

发布时间:2020-12-15 21:03:09 所属栏目:asp.Net 来源:网络整理
导读:我正在使用MVC4并通过nuget添加了Bootstrap和Font Awesome. 我可以看到Bootstrap如何通过下面的BootstrapBundleConfig.cs(由nuget包添加)捆绑在一起: public static void RegisterBundles(){ BundleTable.Bundles.Add(new ScriptBundle("~/bundles/bootstra
我正在使用MVC4并通过nuget添加了Bootstrap和Font Awesome.

我可以看到Bootstrap如何通过下面的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"));
}

我有以下问题:

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

解决方法

您可以阅读有关捆绑如何在 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方法中删除此字符串即可.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读