Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Can';t将HttpFileCollectionBase转换为HttpFileCollection_Asp.net Mvc_File Upload - Fatal编程技术网

Asp.net mvc Can';t将HttpFileCollectionBase转换为HttpFileCollection

Asp.net mvc Can';t将HttpFileCollectionBase转换为HttpFileCollection,asp.net-mvc,file-upload,Asp.net Mvc,File Upload,我有部分看法: <% using (Html.BeginForm("add", "home", FormMethod.Post, new { enctype = "multipart/form-data" })){%> <input name="IncomingFiles" type="file" /> <div class="editor-field"><%: Html.TextBox("TagsInput") %></

我有部分看法:

<% using (Html.BeginForm("add", "home", FormMethod.Post, 
   new { enctype = "multipart/form-data" })){%>
   <input name="IncomingFiles" type="file" />
   <div class="editor-field"><%: Html.TextBox("TagsInput") %></div>
   <p><input type="submit" value="Create" /></p><% } %>
它将无法将我上传的文件与HttpFileCollection匹配,它们将显示为HttpFileCollectionBase。 如何获得视图以向我传递HttpFileCollection

我需要任何特定的参数吗


谢谢大家!

在行动方面做类似的事情。您不能将文件作为参数传递:

[HttpPost]
public ActionResult add(string TagsInput) {
  if (Request.Files.Count > 0) {
    // for this example; processing just the first file
         HttpPostedFileBase file = Request.Files[0];
 if (file.ContentLength == 0) {
      // throw an error here if content length is not > 0
      // you'll probably want to do something with file.ContentType and file.FileName
      byte[] fileContent = new byte[file.ContentLength];
      file.InputStream.Read(fileContent, 0, file.ContentLength);
      // fileContent now contains the byte[] of your attachment...
    }  
  }
  return View();
}
[HttpPost]
public ActionResult add(string TagsInput) {
  if (Request.Files.Count > 0) {
    // for this example; processing just the first file
         HttpPostedFileBase file = Request.Files[0];
 if (file.ContentLength == 0) {
      // throw an error here if content length is not > 0
      // you'll probably want to do something with file.ContentType and file.FileName
      byte[] fileContent = new byte[file.ContentLength];
      file.InputStream.Read(fileContent, 0, file.ContentLength);
      // fileContent now contains the byte[] of your attachment...
    }  
  }
  return View();
}