【发布时间】:2019-10-14 07:13:18
【问题描述】:
我正在尝试将 IFormFile 用作嵌套 ViewModel 中的属性。我在尝试将 ViewModel 绑定到运行时的控制器操作时遇到问题。 AJAX 请求停止并且永远不会到达操作。
这个概念性问题参考了我在IFormFile property in .NET Core ViewModel causing stalled AJAX Request 的具体问题
视图模型:
public class ProductViewModel
{
public ProductDTO Product { get; set; }
public List<ProductImageViewModel> Images { get; set; }
}
嵌套视图模型:
public class ProductImageViewModel
{
public ProductImageDTO ProductImage { get; set; }
public IFormFile ImageFile { get; set; }
}
行动:
[HttpPost]
public IActionResult SaveProduct([FromForm]ProductViewModel model)
{
//save code
}
我想知道 IFormFile 属性是否需要是您绑定到控制器操作的 ViewModel 的直接属性。
IFormFile Documentation 似乎没有回答我的问题。
【问题讨论】:
-
您应该使用 multipart/form-data content-type 并传递表单名称为 Images[0].ImageFile, Images[1].ImageFile 的文件用于多文件上传
标签: c# asp.net-core .net-core