MVC Web应用程序包和脚本,样式呈现

时间:2015-09-23 05:48:33

标签: c# asp.net

我正在开发一个Web应用程序,我有 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视图

使用Asp.net Web应用程序

3 个答案:

答案 0 :(得分:3)

您用于MVC:

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

对于WebForms:

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

答案 1 :(得分:2)

可以这样检查。

@Scripts.Render("~/bundles/WebFormsJs")  
@Scripts.Render("~/bundles/MsAjaxJs")  
@Scripts.Render("~/bundles/jquery")  
@Scripts.Render("~/bundles/jqueryui")  
@Scripts.Render("~/bundles/jqueryval")  

答案 2 :(得分:1)

这应该可以解决问题 确保您的项目安装了Microsoft ASP.Net Web Optimization Framework。

 <script src="<%=BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryui")%>" type="text/javascript"></script>
 <script src="<%=BundleTable.Bundles.ResolveBundleUrl("~/bundles/jquery")%>" type="text/javascript"></script>