我正在尝试使用 ASP.NET Core 1.0 制作一个小型上传文件 api。 我有一个从 MVC5 应用程序中获取的模型:
public class RoomModel
{
public int Id { get; set; }
public string Name { get; set; }
public HttpPostedFileBase Image { get; set; }
}
我想创建一个像这样的函数:
[HttpPost("upload")]
public IActionResult Upload(List<RoomModel> rooms)
{
// Check and upload file here.
// Save parameter to database.
}
在我的 MVC5 中,使用 HttpPostedFileBase 没问题,但在 ASP.NET Core 中,我不知道如何以相同的结果进行存档。
有人可以帮我吗? 谢谢。
P/S:我搜索过类似的教程,但一无所获。我读过的每个教程都只是关于获取键值参数,没有教程是关于将信息放入这样的模型中。
最佳答案
最后,我找到了这篇文章:
http://www.mikesdotnetting.com/article/288/uploading-files-with-asp-net-core-1-0-mvc
从这篇文章开始,我的 RoomModel 将如下所示:
public class RoomModel
{
public int Id { get; set; }
public string Name { get; set; }
public IFormFile Image { get; set; }
}
因此,据我目前所知,IFromFile 取代了 HttpPostedFileBase,处理文件的步骤与 HttpPostedFileBase 相同。
关于asp.net-core-1.0 - 如何使用 ASP.NET Core 1.0 上传带有模型的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36929255/