【发布时间】:2017-08-16 16:54:11
【问题描述】:
重新发布此内容是因为我找不到任何不涉及使用 Google 捆绑包或其他东西的答案。请告诉我是否遗漏任何细节,以便我补充。我的 _Layout 顶部引用了 VS 中包含的整个 jquery 包...
@Scripts.Render("~/bundles/jquery")
这是 BundleConfig.cs
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
...但在这种情况下它仍然告诉我 .each 不是一个函数。我缺少什么或需要参考布局或 BundleConfig?为什么 .each 不是 Visual Studio 2017 附带的 jquery 包的一部分?
@Html.ListBox("Groups", null, new { size = 10, style = "width : 350px; max-width : 500px;", id = "grouplist" })
我的 jquery 的整个上下文:
$('#savegroups').click(function () {
var groupId = $('#groupId').val();
var list = [];
('#grouplist').each(function (item) {
list.append('{"groupId":"' + groupId + '","groupName":"' + item.value +'"}');
});
$.ajax({
type: "POST",
url: "/GroupCategories/EditGroups",
data: JSON.stringify(list),
});
});
错误:
1:230 Uncaught TypeError: "#grouplist".each is not a function
at HTMLInputElement.<anonymous> (1:230)
at HTMLInputElement.dispatch (jquery:1)
at HTMLInputElement.y.handle (jquery:1)
【问题讨论】:
-
将 ('#grouplist') 更改为 $('#grouplist')
-
我试过了,它只是跳过了整个循环。
标签: c# jquery asp.net-core-mvc visual-studio-2017