在控制器上,我的fileName值变为空。我的组件中有这段代码。使用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.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);
}
我的控制器需要一个字符串:
public IActionResult SaveFileToDatabase(string fileName){
答案 0 :(得分:0)
您需要指定POST应该使用FromBody属性从邮件正文中检索fileName:
public IActionResult SaveFileToDatabase([FromBody]string fileName){
答案 1 :(得分:0)
您应该传递具有fileName
属性的对象
this.fileService.saveFileProperties({fileName: this.fileName}).subscribe( //..