轉發此信息是因爲我找不到任何不涉及使用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
我試過了,它只是跳過了整個循環。 –