首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVC 4 Styles.Render & Scripts.Render澄清

MVC 4 Styles.Render & Scripts.Render澄清
EN

Stack Overflow用户
提问于 2014-06-08 11:46:38
回答 1查看 4.7K关注 0票数 3

我在引导下使用ASP.NET MVC 4,我注意到我的项目与许多关于“用引导构建您的站点”的文章和教程略有不同,它们始终提到使用Javascript和CSS (bootstrap.min.css,bootstrap.min.js)的小型化文件,虽然文件在目录中,但我只有这些文件。

我读过这些文件,但我不明白它的意义,也许有人可以澄清它们的使用,如果我需要在包配置中添加它们的引用呢?

我的代码如下所示:

_Layout.cshtml:

代码语言:javascript
复制
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <a href="@Url.Action("Index", "Home")" class="navbar-brand">
                    <span class="glyphicon glyphicon-filter"></span> SelectorIT - OnLine
                </a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>

还有我的BundleConfig.cs:

代码语言:javascript
复制
public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        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"));

        // Set EnableOptimizations to false for debugging. For more information,
        // visit http://go.microsoft.com/fwlink/?LinkId=301862
        BundleTable.EnableOptimizations = true;
    }
}

我有两个问题:

  1. 当我没有参考bootstrap.min.css,bootstrap.min.js时,我遗漏了什么?
  2. 是否应在以下文件中添加对这些文件的引用: Bundles.Add(新StyleBundle(“~/StyleBundle/css”).Include()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-08 12:03:27

min文件删除所有不必要的字符,以使文件更小。这减少了装载时间。来源

如果您正在构建一个小型的个人项目,那么性能可能没有高优先级。如果您正在为其他人或组织构建站点,我建议使用min版本。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24105803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档