File 带有移动项目文件上载的MVC 4测试版不起作用
我正在玩新的MVC4测试版。我使用移动应用程序模板创建了一个新的web项目。我只是添加了一个控制器和一个视图来上传一个文件,但该文件在操作结果中总是空的。这是一个错误,还是我做错了什么? 控制器代码:File 带有移动项目文件上载的MVC 4测试版不起作用,file,mobile,upload,asp.net-mvc-4,File,Mobile,Upload,Asp.net Mvc 4,我正在玩新的MVC4测试版。我使用移动应用程序模板创建了一个新的web项目。我只是添加了一个控制器和一个视图来上传一个文件,但该文件在操作结果中总是空的。这是一个错误,还是我做错了什么? 控制器代码: using System.IO; using System.Web; using System.Web.Mvc; namespace MobileWebExample.Controllers { public class FileUploadController : Controller
using System.IO;
using System.Web;
using System.Web.Mvc;
namespace MobileWebExample.Controllers
{
public class FileUploadController : Controller
{
public ActionResult Index()
{
return View();
}
[AllowAnonymous]
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Upload(HttpPostedFileBase file)
{
int i = Request.Files.Count;
if (file != null)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
}
}
视图如下所示:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<form action="@Url.Action("Upload")" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="submit" value="Submit" />
</form>
我有一个类似的问题,虽然不是手机 替换
public ActionResult Upload(HttpPostedFileBase file)
与
然后可以从集合中访问该文件
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)