My html file index.cshtml is like this
<html>
<head>
</head>
<body>
<form method="post">
<input type="file" name="myfile" id="myfile" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
My controller is like this
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();
}
}
And the error occurred when I posted a file. It told myfile object was null. Please help fixing this. Thx so much !