相关疑难解决方法(0)

HttpPostedFileBase始终在ASP.NET MVC中返回null

我在ASP.NET MVC中上传文件时遇到问题.我的代码如下:

视图:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index2</h2>
@using (Html.BeginForm("FileUpload", "Board", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
  <input type="file" />
  <input type="submit" />
}
Run Code Online (Sandbox Code Playgroud)

控制器:

[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
    if (uploadFile != null && uploadFile.ContentLength > 0)
    {
        string filePath = Path.Combine(Server.MapPath("/Temp"), Path.GetFileName(uploadFile.FileName));
        uploadFile.SaveAs(filePath);
    }
    return View();
}
Run Code Online (Sandbox Code Playgroud)

但uploadFile总是返回null.任何人都可以找出原因??

asp.net-mvc file-upload

53
推荐指数
4
解决办法
8万
查看次数

标签 统计

asp.net-mvc ×1

file-upload ×1