• Asp.net MVC5如何添加BundleConfig.cs到我的项目


    在新建一个空MVC项目时是没有BundleConfig的,但是又想用怎么办呢?

    要添加此文件,首先需要将Microsoft.AspNet.Web.Optimization nuget包添加到您的web项目:

    Install-Package Microsoft.AspNet.Web.Optimization

    然后在App_Start文件夹下创建一个名为BundleConfig.cs的新cs文件。

    using System.Web;
    using System.Web.Optimization;
    
    namespace CodeRepository.Web
    {
        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"));
            }
        }
    }

    然后修改您的Global.asax并在Application_Start()中添加一个对RegisterBundles()的调用:

    using System.Web.Optimization;
    
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

    在页面中调用,如果提示找不到Styles

     

    就到web.config中添加一行
    <add namespace="System.Web.Optimization" />
     
     
  • 相关阅读:
    使用openssl搭建CA并颁发服务器证书
    PKCS#1规范阅读笔记2--------公私钥ASN.1结构
    PKCS#1规范阅读笔记1--------基本概念
    Chrome 扩展机制
    Docker部署zookeeper集群和kafka集群,实现互联
    ASP.NET Identity实现分布式Session,Docker+Nginx+Redis+ASP.NET CORE Identity
    Transmission添加SSL访问
    重磅来袭,水木PC客户端全面改版,欢迎使用!
    CLR via C# 3rd
    IL命令
  • 原文地址:https://www.cnblogs.com/ewyb/p/12186322.html
Copyright © 2020-2023  润新知