c# - 将数字数组从 JS 发送到 asp.net MVC 操作
问题描述
我想将数字数组发送到我的后退操作,无论我尝试什么,我都会得到 NULL 或错误。这是我当前的代码。
JS
$.ajax({
traditional: true,
dataType: "json",
contentType: 'application/json; charset=utf-8',
type: "POST",
data: JSON.stringify(groupIds),
url: '/Admin/ReadMessages',
error: function (error) {
swal.fire({
title: "Something went wrong. Please try again later.",
type: "error"
});
}
});
MVC
public ActionResult ReadMessages(List<long> groupIds)
{
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
有任何想法吗?
解决方案
试试这个
var arr= new Array();
arr.push(1);
arr.push(2);
$.ajax({
type: "POST",
url: urlToPost,
data: JSON.stringify(arr),
contentType: "application/json"
});
推荐阅读
- python - 如何卸载并重新安装 anaconda naviator
- python - 如何在更改文件名时*不*更改文件扩展名?
- julia - 朱莉娅推!需要整个数组的副本
- python - 如何在一个类中定义一个方法来创建同一个类的对象?
- python-3.6 - python3除法和精度
- python - 使用 `.rstrip()` 和 `.strip() 删除换行符 `\n`
- visual-studio-code - Visual Studio Code:如何关闭“在文件”窗格中查找?
- php - 我们如何在 Laravel 8.1 中创建一个普通的控制器(--plain 在新版本中不存在)
- javascript - Firefox preventDefault on mousemove 不起作用
- python - ValueError:无法将字符串转换为浮点数::'30/01/20'