我是mvc的新手,我遇到了问题.我搜遍了所有的答案,我找不到一个,但我很确定有些东西会让我失望.问题是我在将文件上传到App_Data文件夹后不知道如何访问文件.我使用在所有论坛上找到的相同代码:
对于我的观点,我使用它
@using (Html.BeginForm("Index", "Home", FormMethod.Post,
new { enctype="multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="submit" />
}
Run Code Online (Sandbox Code Playgroud)
对于我的控制器,我使用它
public class HomeController : Controller
{
// This action renders the form
public ActionResult Index()
{
return View();
}
// This action handles the form POST and the upload
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
// extract only the fielname
var fileName …
Run Code Online (Sandbox Code Playgroud)