转发此信息是因为我找不到任何不涉及使用Google捆绑包或其他内容的答案。请告诉我,如果我错过了任何细节,我会添加它。我有包含我的_layout顶部引用VS全jQuery的包......('...')。每个都不是一个有效的用于jquery包的mvc核心功能
@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')** – gaetanoM
我试过了,它只是跳过了整个循环。 –