我有两个类,基本上我想用两个存储过程调用两个单独的模型以在两个表中插入数据。我这样写控制器:
[HttpPost]
public IHttpActionResult Adddata([FromBody]IList<Details> details,[FromBody] Request request)
{
var changerequestResponse = db.sp_AddChangerequests(request.EmpID, request.CreatedDate, request.Status).SingleOrDefault();
GenericResponse objResponse = null;
foreach (Details detail in detailss)
{
var data = JsonConvert.SerializeObject(db.sp_AddChangerequestDetails(detailss.CRID, detailss.Category, detailss.Info, detailss.Col, detailss.Reason).SingleOrDefault(), Formatting.Indented, settings);
objResponse = JsonConvert.DeserializeObject<GenericResponse>(data);
}
return Ok(objResponse);
}
和我的控制器js文件如下:
$scope.SubmitrequestForm = function(){
console.log($scope.changereqcol);
var req = {
method: 'POST',
url: WebApiUrl + 'Adddata',
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify($scope.changereqcol)
}
console.log()
$http(req).then(function (data, status) {
console.log(data);
}, function (err, status) {
console.log(err);
});
};
当我尝试提交数据时,我遇到了以上错误。你能告诉我我在想什么吗
答案 0 :(得分:1)
来自this来源:
对于每种操作方法,请勿将[FromBody]应用于多个参数。输入格式器读取请求流后,将不再可以再次读取该流以绑定其他[FromBody]参数。
答案 1 :(得分:0)
请查看键中的jQuery POST方法:值设置数据
function verifyRiderAppID() {
$.post("/url ", {
Parms: value
},
function (data, status) {
if (status === 'success') {
} else {
//else logic
}
});
}