我可以在.net 4 Asp.Net Web应用程序中使用Bundling [Bundle.Config] [英] Can i use Bundling [Bundle.Config] in .net 4 Asp.Net web Application

查看:94
本文介绍了我可以在.net 4 Asp.Net Web应用程序中使用Bundling [Bundle.Config]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在.Net framework 4.它是一个Asp.Net Web Application.i需要使用Bundle.Config才能使用Bundling功能。

I have my application in .Net framework 4.It is a Asp.Net Web Application.i need to use Bundle.Config in order to use Bundling feature.

我已经阅读了许多文档,说它是.Net框架4.5中的功能,以及Asp.Net MVC应用程序中的功能。

I have read many documents saying that, it is feature in .Net framework 4.5 and that to in Asp.Net MVC Application.

我需要为Scripts创建一个包在aspx页面中。
我可以在我的文件中包含Bundle.Config,以便Bundling工作。

I need to make a bundle for Scripts in aspx pages. Can i include Bundle.Config in my file so that Bundling works.

推荐答案

是的,你可以使用捆绑ASP.net 4.使用 Nuget Package Manager Microsoft ASP.Net Web Optimization Framework 安装到您的项目中。然后在 global.asax 中注册 Application_Start 方法中的包。这样的事情 -

Yes, you can use bundling in ASP.net 4. Use Nuget Package Manager to install Microsoft ASP.Net Web Optimization Framework to your project. Then in global.asax register the bundles in Application_Start method. something like this -

    var jqueryBundle = new ScriptBundle("~/Scripts/jquery");
    jqueryBundle.Include(new string[] { 
        "~/Scripts/jquery-1.8.3.js",
        "~/Scripts/jquery-ui-1.9.1.custom.min.js",
        "~/Scripts/jquery-ui-timepicker-addon.js",
        "~/Scripts/jquery.validate.js",
        "~/Scripts/jquery.validate-additional-methods.js"
    });

    BundleTable.Bundles.Add(jqueryBundle);

然后在 aspx 页面或主页调用包 -

Then in your aspx page or masterpage call the bundle-

    <%= System.Web.Optimization.Scripts.Render("~/Scripts/jquery") %>

这篇关于我可以在.net 4 Asp.Net Web应用程序中使用Bundling [Bundle.Config]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆