【问题标题】:Mvc .net: Upload Multiple files in multiple fields via one http postMvc .net:通过一个http帖子上传多个字段中的多个文件
【发布时间】:2013-08-22 16:23:27
【问题描述】:

我有模型,具有三个属性:

  1. IEnumerable<File> photos
  2. IEnumerable<File>Logos
  3. File Video

我可以通过 POST 方法将此模型发布到控制器吗?如何配置以获取控制器中的文件?

【问题讨论】:

    标签: asp.net-mvc post file-upload controller http-post


    【解决方案1】:

    查看:

    <input type="file" name="Photos">
    <input type="file" name="Photos">
    <input type="file" name="Logos">
    <input type="file" name="Logos">
    <input type="file" name="Video">
    

    您可以使用 javascript 填充上传者。

    控制器:

        [HttpPost]
        public ActionResult Create(
           ViewModel model,
           IEnumerable<HttpPostedFileBase> Photos,
           IEnumerable<HttpPostedFileBase> Logos,
           HttpPostedFileBase Video )
        {
           ...
        }
    

    我们还可以通过 View Model 发布上传的文件,这样更简洁。详情请查看this

    【讨论】:

      猜你喜欢
      • 2010-12-14
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 2019-01-29
      • 2019-12-23
      相关资源
      最近更新 更多