【问题标题】:HttpPostedFileBase has error (MVC) red underlineHttpPostedFileBase 有错误 (MVC) 红色下划线
【发布时间】:2020-03-24 14:50:44
【问题描述】:

我无法使用 HttpPostedFileBase,因为我在控制器操作中的 HttpPostedFileBase 下有红色下划线。我该如何解决?

 public IActionResult Add(TheMobileSuit themobilesuits, HttpPostedFileBase photo)

【问题讨论】:

  • 我错过了什么??
  • 你的意思是我应该将 HttpPostedFileBase 替换为 IFormFile??
  • 欢迎来到 SO - 由于无用的文本,请删除上面的 cmets(请参阅:我该如何解决?)并复制(请参阅您对答案的评论)。

标签: c# image model-view-controller controller


【解决方案1】:

如果您使用的是 .Net Framework,则需要确保您的项目引用 System.Web.Abstractions。如果您使用的是 .Net Core,则需要使用 IFormFile,因为 Core 中不存在 HttpPostedFileBase

IFormFile:https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iformfile?view=aspnetcore-3.0

HttpPostedFileBase:https://docs.microsoft.com/en-us/dotnet/api/system.web.httppostedfilebase?view=netframework-4.8

【讨论】:

  • 你的意思是我应该将 HttpPostedFileBase 替换为 IFormFile??
  • 如果您使用的是 .Net Core,可以。
  • 如何使用IFormFile保存和上传图片文件?我必须编码什么?图像应保存到 wwwroot 下的文件夹 (Images),然后将图像的路径名 (~/Images.example.jpg) 保存到我的本地数据库。
  • 这里似乎有一些非常好的文档用于在 .Net Core 中上传文件:docs.microsoft.com/en-us/aspnet/core/mvc/models/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-02
  • 1970-01-01
  • 1970-01-01
  • 2020-07-29
相关资源
最近更新 更多