这是我的服务器端代码.
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); }
键入Script类
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
upload(file: file,questionText: string): Observable<fileResponseModel> { const url: string = Urls.uploadfiles(); const formData: FormData = new FormData(); formData.append('attachment',file,file.name); formData.append('questionText',questionText); const options = { headers: new httpheaders().set('enctype','multipart/form-data') }; return this.httpService.post(url,formData,options);}总结
以上是内存溢出为你收集整理的使用asp.net core 2.0中的angular 5进行文件上传.文件为空全部内容,希望文章能够帮你解决使用asp.net core 2.0中的angular 5进行文件上传.文件为空所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)