使用ASP将复杂的模型表数据返回到控制器.Net MVC 4

本文关键字:返回 控制器 Net MVC 数据 ASP 复杂 模型 使用 | 更新日期: 2023-09-27 18:06:58

这是我的场景。我有一个模型,其中包含具有附加视图属性和实体属性的对象列表。包含此模型的视图遍历从对象属性构建表行的列表。

模型
public class DownloadableFileGroupViewModel
{
    public List<DownloadableFileViewModel> Files { get; set; }
}

列表对象
public class DownloadableFileViewModel
{
    public DownloadableFile File { get; set; }
    public bool Selected { get; set; }
}

实体
public class DownloadableFile
{
    public int ID { get; set; }
    public string Title { get; set; }
    [Display( Name="File" )]
    public string FileName { get; set; }
    public int DownloadableFileGroupID { get; set; }
}

下面是构建表的视图的一个片段:http://codeshare.io/ks8c1

最后,在我的控制器中有一个简单的Post函数:
public ActionResult ImageDownloadArea(DownloadableFileGroupViewModel model)
{
    return View(model);
}

我遇到的问题是模型。我的控制器中的文件总是空的。我应该如何构建我的表单,以便模型绑定器重建模型并将其提供给控制器?

使用ASP将复杂的模型表数据返回到控制器.Net MVC 4

尝试在控制器中使用HttpPostedFileBase代替DownloadableFileGroupViewModel

public ActionResult ImageDownloadArea( IEnumerable < HttpPostedFileBase > model )
{
   return View( model );
}

同时将enctype = "multipard/form-data"更改为enctype = "multipart/form-data"

尝试在视图中使用List作为模型。