C# 角度服务调用的值为Null
我在控制器上的文件名值为null。我从我的组件中得到了这个代码。使用Angular 7和.net core 2.1C# 角度服务调用的值为Null,c#,angular,asp.net-core,C#,Angular,Asp.net Core,我在控制器上的文件名值为null。我从我的组件中得到了这个代码。使用Angular 7和.net core 2.1 handleFileInput(event) { const file = event.target.files[0]; this.fileName = file.name; console.log('This file - ' + this.fileName); this.route.params.subscribe(params => { this.fileSe
handleFileInput(event) {
const file = event.target.files[0];
this.fileName = file.name;
console.log('This file - ' + this.fileName);
this.route.params.subscribe(params => {
this.fileService.getHeaders().subscribe((data: IApiHelper) => {
this.fileService.createHeader(data);
this.fileService.saveFileProperties(this.fileName).subscribe(s => {
console.log('this is inside subscribe - ' + s);
this.fileName = s;
},
(error) => { console.log(error); }
);
});
})
}
这是服务代码:
saveFileProperties(fileName: string ) {return this.http.post<string>('/api/aspera/SaveFileToDatabase',fileName, this.httpOptions);
您需要指定POST应使用FromBody属性从邮件正文中检索文件名:
public IActionResult SaveFileToDatabase([FromBody]string fileName){
您应该传递一个具有
fileName
属性的对象
this.fileService.saveFileProperties({fileName: this.fileName}).subscribe( //..
this.fileService.saveFileProperties({fileName: this.fileName}).subscribe( //..