Skip to main content
 首页 » 编程设计

c#之MVC Web 应用程序包和脚本、样式呈现

2024年01月26日29mfrbuaa

我正在开发一个网络应用程序并且我有这个Bundle Config

using System.Web; 
using System.Web.Optimization; 
 
namespace WebApplication3 
{ 
    public class BundleConfig 
{ 
    public static void RegisterBundles(BundleCollection bundles) 
    { 
        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")); 
 
        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")); 
 
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 
                    "~/Scripts/jquery-{version}.js")); 
 
        bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( 
                    "~/Scripts/jquery-ui-{version}.js")); 
 
        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( 
                    "~/Scripts/jquery.unobtrusive*", 
                    "~/Scripts/jquery.validate*")); 
 
        } 
    } 
} 

这是我的查看页面之一:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
      <title></title> 
<script> 
 <-- This?? --> 
</script> 

我怎样才能渲染这些包?我正在使用使用 asp.net aspx View 的 Asp.net Web 应用程序

请您参考如下方法:

您用于 MVC:

@Scripts.Render("~/bundles/WebFormsJs") 

对于 WebForms:

<%: Scripts.Render("~/bundles/WebFormsJs") %>