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();
}