2017-09-01 93 views
0

BundleConfig:Web表單頁面上捆綁不註冊腳本

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> 

我也有安裝在我的項目的網絡優化。爲什麼沒有在頁面上呈現任何腳本/樣式?

bundle config中的文件路徑引用了正確的文件,所以我不知道它爲什麼不起作用。

+1

至於樣式,似乎你沒有在任何地方註冊「〜/ Content/css」。而且<%Scripts ....等缺少冒號。它應該讀取<%:Scripts.Render –

+1

除非你有在Bundle.Config當然配置的樣式:) –

+0

@FrankWitte Riiight,你可以看到我有點新的Web窗體和aspx。我想念我的MVC和剃刀:(如果你把你的評論放入答案中,我會選擇它作爲答案 – Andrew

回答

1

<% Scripts....等缺少冒號。 它應該是<%: Scripts.Render