【发布时间】:2021-11-28 19:06:12
【问题描述】:
我通过一个循环获取一个数组,并通过一个 ajax 调用将它传递给我的 c# 方法,但由于某种原因,我只在我的参数中获取空值,但数组的计数是通过的。我不确定我做错了什么。例如,在通过 ajax 传递它之前的数组的计数为 3,每个键都填充了所需的信息,但是当我通过 ajax 调用传递它并在 VS 上调试时,我的列表的参数为 null 但有一个计数3 个?
let test = $('.divtest').map(function (index, element) {
return {
key1: $(element).closest('.testdiv')[0].id,
key2: $(element).attr('id'),
key3: $(element).attr('style')
}
}).get();
Ajax 调用
$.ajax({
cache: false,
type: "POST",
data: { test: test},
dataType: "json",
url: "/controller/testhere",
success: function (result) {
alert('done');
}
});
C#方法
public JsonResult testhere(List<string> test)
{
//stuff
return null;
}
【问题讨论】:
-
试试
url: "/controller/testhere?text="+JSON.stringify(test) -
呵呵,请问为什么要尝试这种方法? @Vadim
标签: javascript c# arrays json ajax