asp.net-core-1.0 - 如何使用 ASP.NET Core 1.0 上传带有模型的文件?

标签 asp.net-core-1.0

我正在尝试使用 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/

相关文章:

c# - HttpContext.Authentication.SignOutAsync 不会删除身份验证 cookie

asp.net-core - 如何使用 Entity Framework 添加具有 REST 操作的 API Controller ?

asp.net-core - 命名空间 'Microsoft.AspNetCore' 中不存在标识

typescript - ASP.NET 核心项目 : How to keep Typescript from Compiling

c# - 在 mvc 中使用 IViewLocationExpander

session - “IServiceCollection”不包含 'AddSession' 的定义

xamarin.android - 如何在ASP.NET Core 1.0 RC2项目中使用PCL

asp.net - 如何在ASP.NET Core 1.0中获取bin文件夹

visual-studio-2015 - 无法使以下项目可运行(未将对象引用设置为对象的实例。)

c# - ASP.NET Core RC2 种子数据库