javascript - 如何通过ajax将两个数组发送到控制器
问题描述
我尝试将两个数组发送到控制器,每个数组来自不同的类。但我得到的只是一条错误消息的警报。我究竟做错了什么?当我在 ajax 数据中只发送一个数组时,它在控制器的第一个数组中得到很好。我的代码js:
$("#Button2").click(function () {
var dict = new Array();
$(":checkbox").each(function () {
if ($(this).prop("checked")== true) {
var key = this.name
if ($("input[name = 'r" + key + "']").length) {
dict.push({
Code: key,
Reccomendation: $("input[name = 'r" + key + "']").prop("value"),
});
}
else{
dict.push({
Code: key,
Reccomendation: $(this).prop("value"),
});
}
}
}) //end function each
var dict2 = new Array();
dict2.push({
Mentioned: $("#yesno").val(),
FollowUp: $("#Follo").val(),
UpdateCode:5
})
$.ajax({
type: 'POST',
url: "@Url.Action("SavevisitSummary")",
traditional: true,
dataType: 'JSON',
contentType: 'application/json; charset=utf-8',
data: { 'a': JSON.stringify(dict), 'b': JSON.stringify(dict2) },
success: function () {
alert("sucssec")
},
error:function(){
alert("error")
}
})
})
控制器看起来像:
public ActionResult SavevisitSummary(Reccomendations[] a, Summary[] b) { }
解决方案
推荐阅读
- flutter - 焦点时如何更改 TextFiled 小部件背景颜色
- javascript - 当我通过浏览器发出请求时,Agora 云录制 api https://api.agora.io/v1/apps/:api_id/cloud_recording/acquire CORS 块
- python - 使用python在txt文件中查找字符串的最佳方法是什么?
- kotlin - 如何从 Kotlin 中的另一个类访问变量值?
- google-cloud-platform - 如何使用 GQL 查询以查找具有重复值的列/实体
- c++ - 在向量中查找大于 0(或一般 k)的最小元素的最佳方法是什么?
- php - 由于不活动,该页面已过期。请刷新并重试。“在我登录后在我的生产托管 cpanel 中”laravel 5.5
- php - 在 DataTable 服务器端处理中调用函数
- magento2 - Magento 2.3 Ubuntu 的 Venia 店面设置
- ruby-on-rails - Sidekiq 完成执行作业后,如何更新类实例的状态?