Ajax 无法使用带有 2D 数组参数的 C# 控制器操作
Ajax Not Working With C# Controller Action With 2D Array Parameter
我的 Ajax 没有命中我的控制器操作。可能是什么原因?
我的控制器操作
public ActionResult Save_Data(string [][] rosterArray, int Pricelist_Id, int Group_Id)
我的阿贾克斯
$.ajax({
url: '@Url.Action("Save_Data", "PriceListMaster")',
type: 'Post',
async: false,
contentType: 'application/json',
dataType: "json",
data: { "rosterArray": rosterArray, "Pricelist_Id": "2", "Group_Id": $("#Group_Id").val() },
//data: JSON.stringify({ "Item_Code": Item_Code, "IPD_Price": IPD_Price, "OPD_Price": OPD_Price, "EMS_Price": EMS_Price }),
success: function (data) {
debugger
if (data.success)
{
alert('Data Saved Successfully.');
location.reload();
} else {
alert(data.error_msg);
}
}
}
如果在 AJAX 中使用type: 'Post'
,这意味着您需要在控制器中添加请求类型。
尝试在控制器中使用它,
[HttpPost]
public ActionResult Save_Data(string [][] rosterArray, int Pricelist_Id, int Group_Id)
使用方法中的httpPost
定义响应类型。
在
客户端
$.ajax({
url: '@Url.Action("Save_Data", "PriceListMaster")',
type: 'Post',
async: false,
contentType: 'application/json',
dataType: "json",
data: { "rosterArray": JSON.stringify(rosterArray), "Pricelist_Id": "2", "Group_Id": $("#Group_Id").val() },
//data: JSON.stringify({ "Item_Code": Item_Code, "IPD_Price": IPD_Price, "OPD_Price": OPD_Price, "EMS_Price": EMS_Price }),
success: function (data) {
debugger
if (data.success)
{
alert('Data Saved Successfully.');
location.reload();
} else {
alert(data.error_msg);
}
}
}
您的控制器代码可以是这样的:
[HttpPost]
public ActionResult Save_Data(string rosterArray, int Pricelist_Id, int Group_Id)
{
string [][] convertedArray = JsonConvert.DeserializeObject<string [][]>(rosterArray);
}
希望这有效注意:但您需要包括using Newtonsoft.Json;
相关文章:
- 从node.js向CasperJS传递参数数组
- 如何从参数数组中调用回调
- 传递参数数组而不更改此项
- 在参数数组中传递整数数组
- 如何在JavaScript中获取字符串表示的参数数组
- 使用包含参数数组的数组调用函数,而不是仅列出数组
- JavaScript 修改 URL 参数数组
- 如何将参数数组传递给 JavaScript 中的另一个函数
- 传递参数数组
- 带有函数参数数组的闭包
- 将 JavaScript new 关键字与可变长度参数数组一起使用
- JavaScript:为什么更改参数变量会更改“参数”“数组”
- 如果使用参数数组调用,则日期会更改结果
- 试图理解Javascript中参数数组的概念
- Javascript:如何使用apply方法传递参数数组,然后在被调用的函数中访问它
- 发送单个参数与参数数组
- Array.from(arguments)是创建参数数组的一种可接受的方法
- 函数参数数组,如何影响reference =[]或reference.concat(array2)
- 在javascript中构建参数数组
- Javascript:是已弃用的参数数组