我正在asp.net mvc中开发一个应用程序,我想上传一个文件。在视图方面,当我的视图调用控制器时,我在运行时渲染上传文件字段,它提供FormCollection和控制器端的所有数据,我只能以字符串和请求的形式获取上传文件的名称.File [0] .count等于零。现在我如何解决这个问题。
代码可以按需分享。
此致
答案 0 :(得分:2)
尝试在View
:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" id="file" name="file" />
<input type="submit" value="upload" />
}
在controller
文件中:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
return View();
}