【发布时间】:2018-07-21 18:05:02
【问题描述】:
我正在尝试在 asp.net core 2.0 中使用 angular 5 上传文件。
这是我的服务器端代码。
public class QuestionViewModel
{
public Guid QuestionId { get; set; }
public string QuestionText { get; set; }
public DateTime CreateDate { get; set; }
public string PictureUrl { get; set; }
public FormFile FileUpload { get; set; }
}
这里是控制器方法。
[HttpPost]
[AllowAnonymous]
public JsonResult QuestionPhotoPost([FromBody] QuestionViewModel model)
{
GenericResponseObject<List<QuestionViewModel>> genericResponseObject = new GenericResponseObject<List<QuestionViewModel>>();
genericResponseObject.IsSuccess = false;
genericResponseObject.Message = ConstaintStingValue.TagConnectionFailed;
List<QuestionViewModel> questionViewModel = new List<QuestionViewModel>();
return Json(genericResponseObject);
}
类型脚本类
export class Data {
QuestionText: string = "";
FileUpload: File;
}
这里是 http 调用。该调用是对控制器方法的调用。
public QuestionPostHttpCall(_loginVM: QuestionVmData): Observable<QuestionPhotoViewModel> {
console.log(_loginVM)
const headers = new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8');
return this._httpClientModule.post<QuestionPhotoViewModel>(this.questionPhoto, _loginVM, { headers});
}
这是发送到服务器之前的数据。
但在控制器中,文件的值为 null。
其他属性绑定到控制器参数只有文件不绑定。
谁能告诉我我在哪里做错了。 参考资料 - ASP.NET Core 2.0 and Angular 4.3 File Upload with progress
【问题讨论】:
标签: asp.net asp.net-mvc angular typescript asp.net-core