asp.net mvc 4 使用ScriptBundle打包JS文件有关问题。无法引用js文件
asp.net mvc 4 使用ScriptBundle打包JS文件问题。无法引用js文件
两段代码 一段打包JS, 一段打包CSS 再页面运行之后 效果如下
求大神为我解答啊, 我不想在每个页面上都写script来引用js ,是哪里写的不对?
------解决方案--------------------
Refer this:
http://www.cnblogs.com/insus/p/3360918.html
------解决方案--------------------
用没有 min 的js文件
~/Scripts/jquery-1.7.1.min.js 应该引用不带min的
------解决方案--------------------
bundle只是打包,如果你要在页面上引入打包的代码,得用Scripts.Render或Styles.Render方法才行,象这样:
<link href="/Content/themes/icon.css" rel="stylesheet"/>
@Styles.Render("~/Content")
@Scripts.Render("~/Script/jq")
</head>
顺便说一下,你的css打包成/Content这样的话肯定会出问题,因为路径变了,css文件中引用的背景图片等都会无法显示,因为找不到原来的图片路径了,你得用类似于这样的路径:
bundles.Add(new StyleBundle("~/Content/themes/default/css").Include("~/Content/themes/default/easyui.css"));
bundles.Add(new ScriptBundle("~/Script/jq").Include("~/Scripts/jquery-1.7.1.min.js", "~/Scripts/EasyUI/jquery.easyui.min.js"));
bundles.Add(new StyleBundle("~/Content").Include("~/Content/themes/default/easyui.css", "~/Content/themes/icon.css"));
两段代码 一段打包JS, 一段打包CSS 再页面运行之后 效果如下
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<title>主页 - 我的 ASP.NET MVC 应用程序</title>
<link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
<link href="/Content/themes/default/easyui.css" rel="stylesheet"/>
<link href="/Content/themes/icon.css" rel="stylesheet"/>
<!--为什么这里的JS文件引用没看到,ScriptBundle没有成功?-->
</head>
求大神为我解答啊, 我不想在每个页面上都写script来引用js ,是哪里写的不对?
------解决方案--------------------
Refer this:
http://www.cnblogs.com/insus/p/3360918.html
------解决方案--------------------
用没有 min 的js文件
~/Scripts/jquery-1.7.1.min.js 应该引用不带min的
------解决方案--------------------
bundle只是打包,如果你要在页面上引入打包的代码,得用Scripts.Render或Styles.Render方法才行,象这样:
<link href="/Content/themes/icon.css" rel="stylesheet"/>
@Styles.Render("~/Content")
@Scripts.Render("~/Script/jq")
</head>
顺便说一下,你的css打包成/Content这样的话肯定会出问题,因为路径变了,css文件中引用的背景图片等都会无法显示,因为找不到原来的图片路径了,你得用类似于这样的路径:
bundles.Add(new StyleBundle("~/Content/themes/default/css").Include("~/Content/themes/default/easyui.css"));