相关疑难解决方法(0)

IFormFile 作为嵌套的 ViewModel 属性

我正在尝试使用 IFormFile 作为嵌套 ViewModel 中的属性。我在尝试在运行时将 ViewModel 绑定到控制器操作时遇到了问题。AJAX 请求停止并且永远不会到达操作。

这个概念性问题参考了我在 .NET Core ViewModel中的IFormFile 属性中导致停滞的 AJAX 请求的特定问题

视图模型:

public class ProductViewModel
{
    public ProductDTO Product { get; set; }
    public List<ProductImageViewModel> Images { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

嵌套视图模型:

public class ProductImageViewModel
{
    public ProductImageDTO ProductImage { get; set; }
    public IFormFile ImageFile { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

行动:

[HttpPost]
public IActionResult SaveProduct([FromForm]ProductViewModel model)
{
    //save code
}
Run Code Online (Sandbox Code Playgroud)

我想知道 IFormFile 属性是否需要是您绑定到控制器操作的 ViewModel 的直接属性

IFormFile文档似乎并没有回答我的问题。

c# .net-core asp.net-core

7
推荐指数
1
解决办法
1818
查看次数

IFormFile在ASP.NET Core 2.1中始终返回null

api方法如下图

    [HttpPost]
    public async Task<BaseListResponse<MediaStorageModel>> MediaBrand(IFormFile file, int brandId)
    {
        var files = new List<IFormFile>();
        files.Add(file);

        var response = await this.Upload(files, "brand", brandId);

        return response;
    }
Run Code Online (Sandbox Code Playgroud)

我的邮递员配置 在此处输入图片说明

将我的dotnet核心从2.0升级到2.1不能正常工作,任何人都可以帮忙。出什么事了

c# asp.net asp.net-web-api asp.net-core asp.net-core-webapi

3
推荐指数
5
解决办法
3815
查看次数