Webforms捆绑不在页面上注册脚本

时间:2017-09-01 16:47:57

标签: asp.net vb.net bundling-and-minification

BundleConfig:

Public Class BundleConfig
    ' For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
    Public Shared Sub RegisterBundles(ByVal bundles As BundleCollection)
        bundles.Add(New ScriptBundle("~/bundles/WebFormsJs").Include(
                        "~/Scripts/WebForms/WebForms.js",
                        "~/Scripts/WebForms/WebUIValidation.js",
                        "~/Scripts/WebForms/MenuStandards.js",
                        "~/Scripts/WebForms/Focus.js",
                        "~/Scripts/WebForms/GridView.js",
                        "~/Scripts/WebForms/DetailsView.js",
                        "~/Scripts/WebForms/TreeView.js",
                        "~/Scripts/WebForms/WebParts.js"))

        ' Order is very important for these files to work, they have explicit dependencies
        bundles.Add(New ScriptBundle("~/bundles/MsAjaxJs").Include(
                "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
                "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
                "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
                "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"))

        ' 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/jquery").Include(
                        "~/Scripts/jquery-{version}.min.js"
                    ))

        bundles.Add(New ScriptBundle("~/bundles/bootstrap").Include(
                        "~/Scripts/bootstrap.min.js"
                    ))

        ScriptManager.ScriptResourceMapping.AddDefinition("respond", New ScriptResourceDefinition() With {
                .Path = "~/Scripts/respond.min.js",
                .DebugPath = "~/Scripts/respond.js"})

    End Sub
End Class

申请开始:

Sub Application_Start(sender As Object, e As EventArgs)
        ' Fires when the application is started
        RouteConfig.RegisterRoutes(RouteTable.Routes)
        BundleConfig.RegisterBundles(BundleTable.Bundles)
        BundleTable.EnableOptimizations = True
        Dim builder = New ContainerBuilder()

        RegisterTypes(builder)

        'Setup container with builder
        _containerProvider = New ContainerProvider(builder.Build())
    End Sub

主页头:

<head runat="server">
    <title></title>
    <!-- standard NCCI meta tags -->
    <meta name="AUTHOR" content="NCCI" />
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
    <meta http-equiv="PRAGMA" content="NO-CACHE" />
    <meta name="ROBOTS" content="NONE" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <asp:PlaceHolder runat="server">
        <% Styles.Render("~/Content/css") %>
        <% Scripts.Render("~/bundles/jquery") %>
        <% Scripts.Render("~/bundles/bootstrap") %>
    </asp:PlaceHolder>
</head>

我的项目中也安装了Web优化。为什么页面上没有任何描述/样式?

bundle config中的文件路径引用了正确的文件,因此我不知道它为什么不起作用。

1 个答案:

答案 0 :(得分:2)

<% Scripts....等缺少冒号。 它应该是<%: Scripts.Render