【发布时间】:2019-02-25 17:12:23
【问题描述】:
我已经编写了从 angular 7 到 asp.net core web API 的 Http 邮政编码。 我在下面附上了代码 sn-ps。我在 .net 核心 API 中得到一个空数组。 这是我在 Angular 7 中用 Component.ts 文件编写的代码
saveEducation(edu: Education[]) { const obj = new Education(this._http,
this._deoServices);
obj.saveEducation(edu).pipe(takeUntil(this.destroy$)).subscribe((res) =>
{
// this.eduData = res;
});
}
这是用组件模型类编写的代码
saveEducation(edu: Education[]) {
return this._service.saveEducation('/api/Deo/SaveEducation', edu);
}
这是写在service.ts文件中的代码。
public saveEducation(api: string , model: Education[]): Observable<boolean>
{
return this._http.post<boolean>(api, {education: model.values}, {
headers: new HttpHeaders({
'Content-Type' : 'application/json'
})
});
}
这是接受数组的 Web API 代码。
public bool SaveEducation( dynamic[] edu)
{
var obj = new Candidate_Educational_Info_Table(_context);
return obj.SaveEducation(edu);
}
当我的数组为空时,请帮助我找出错误
【问题讨论】:
-
返回布尔值不是 JSON
-
那我应该返回什么?如果数据发布成功,我将返回 true 或 false
-
你为什么返回true或false?你的目标是什么?
-
不是这样的目标。我可以删除布尔值,但我应该使用什么返回类型?
-
我遇到的问题是错误是在我的 Angular 代码中还是在 Web api 代码中,因为当我从 Angular 调试和发布数据时,我在 Web api 中得到空数组
标签: c# angular asp.net-web-api asp.net-core asp.net-core-2.1