angular http post:
$http({
contentType: "application/json; charset=UTF-8",
url: "myCSharpMethod",
method: "POST",
data: myData, // this is my 2D array ( myData[[],[]] )
traditional: true
})
.success(function(response){
console.log(response)};
我的c#controller:
public string myCSharpMethod(string[][] myData){
return myData[0][0];
}
我的问题是来自post.success的控制台日志是一个空异常错误。请帮忙。
答案 0 :(得分:0)
尝试在帖子中使用JSON.stringify
:
$http({
contentType: "application/json; charset=UTF-8",
url: "myCSharpMethod",
method: "POST",
data: JSON.stringify(myData), // this is my 2D array ( myData[[],[]] )
traditional: true
})
创建视图模型并发送它而不仅仅是数组本身总是一个好主意:
public class MyViewModel
{
public string[][] TableData { get; set; }
}
您的方法签名将更改为:
public string myCSharpMethod([FromBody] MyViewModel myData){
return myData.TableData[0][0];
}