【发布时间】:2018-12-25 22:34:51
【问题描述】:
我的应用程序可以调试并在本地调用 jquery 3.3.1 但在发布应用程序后一切正常 javascrips 和 css 但我的下拉菜单需要 jquery 不起作用。我想在视图页面中使用此捆绑包,不要在布局中使用请帮助我... 我的 budlens 课程包括
public static void Registerbundles(BundleCollection bundles)
{
bundles.IgnoreList.Clear();
//jquery
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js")
.Include("~/Scripts/jquery-3.3.1.js")
.Include("~/Scripts/jquery-3.3.1.min.js")
.Include("~/Scripts/jquery-3.3.1.slim.js")
.Include("~/Scripts/jquery-3.3.1.slim.min.js")
.Include("~/Scripts/jquery-3.3.1.slim.min.map")
.Include("~/Scripts/jquery-3.3.1-vsdoc.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.validate*"));
// java script
bundles.Add(new ScriptBundle("~/bundles/scripts").Include("~/Scripts/bootstrap.js")
.Include("~/Scripts/bootstrap.min.js")
.Include("~/Scripts/jalaali.js")
.Include("~/Scripts/jquery.Bootstrap-PersianDateTimePicker.js"));
// bootsrtap CSS
//bundles.Add(new StyleBundle("~/bundles/css").IncludeDirectory("~/Content/", "*.css", true));
bundles.Add(new StyleBundle("~/bundles/css").Include("~/Content/bootstrap.min.css",
"~/Content/bootstrap.theme.min.css" ,
"~/Content/site.css",
"~/Content/bootstrap.css",
"~/Content/bootstrap.theme.css",
"~/Content/jquery.Bootstrap-PersianDateTimePicker.css"
));
BundleTable.EnableOptimizations = true;
}
并在视图中调用...
<script src="~/bundles/jQuery" type="text/javascript"></script>
<script src="~/bundles/scripts" type="text/javascript"></script>
<link href="~/bundles/css" rel="stylesheet" />
【问题讨论】:
-
你确定捆绑使用
src/href这样的模式吗?通常它使用System.Web.Optimization.Scripts.Render("~/bundles/jQuery")(用于JS文件)或System.Web.Optimization.Styles.Render("~/bundles/css")(用于CSS文件)。 -
感谢您的回复。我检查了这个命令,但没有任何改变...
-
使用浏览器的开发工具(F12),检查控制台和网络选项卡。如果您有任何错误,请将它们作为详细信息包含在内。即使您使用
Render(),样式表和JS脚本仍然无法正常工作? -
即使我使用渲染仍然无法正常工作,我在 consol 中有 2 个错误
1 lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/… 加载资源失败:net::ERR_NAME_NOT_RESOLVED
2 加载资源失败:服务器响应状态为 404(未找到)
3 加载资源失败:服务器响应状态为 404(未找到)@TetsuyaYamamoto -
通常我使用
*这样的通配符:bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-*")。它将包含所有 jQuery 脚本,并且适用于本地和生产机器。
标签: asp.net html asp.net-mvc-5