【发布时间】:2018-10-14 14:30:23
【问题描述】:
我的html文件index.cshtml是这样的
<html>
<head>
</head>
<body>
<form method="post">
<input type="file" name="myfile" id="myfile" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
我的控制器是这样的
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase myfile)
{
string currentdir = Directory.GetCurrentDirectory();
myfile.SaveAs(currentdir + "\\" + myfile.FileName);
return View();
}
}
当我发布文件时发生了错误。它告诉 myfile 对象为空。请帮助解决这个问题。太感谢了!
【问题讨论】:
-
在表单标签中使用 enctype="multipart/form-data"
标签: c# asp.net asp.net-mvc model-view-controller