本文介绍了“无法将多个参数绑定到请求的内容."在Web API和angularJs中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当多个参数传入WebApi
时,它会作为异常"Can't bind multiple parameter to the request's content."
.对于以下代码有任何解决方案
When Multiple parameters pass in WebApi
it results as an exception "Can't bind multiple parameter to the request's content."
.Have any solution for following code
public class A1
{
public int id {get;set;}
public string name {get;set;}
}
public class A2
{
public int id2 {get;set;}
public string name2 {get;set;}
}
[Route("Save")]
[HttpPost]
public string Save([FromBody]A1 Emp, [FromBody]List<A2> EmpMarks)
{
}
JS文件
$http({
method: "post",
url: "/api/Employee/Save",
data: JSON.stringify({
Emp: $scope.Emp,
EmpMarks: $scope.EmpMarks
})
}).then(function (response) {
}, function () {
alert("Error Occur");
})
推荐答案
您可能想使用包含数据的模型:
You might want to use a model which contains your data:
public class A1
{
public int id { get; set; }
public string name { get; set; }
}
public class A2
{
public int id2 { get; set; }
public string name2 { get; set; }
}
public class AModel
{
public A1 Emp { get; set; }
public A2 EmpMarks { get; set; }
}
[Route("Save")]
[HttpPost]
public string Save(AModel aData)
{
// ... your logic here
}
这篇关于“无法将多个参数绑定到请求的内容."在Web API和angularJs中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!