У меня есть простой контроллер с двумя действиями:
public class TestController : Controller
{
// /Test
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
bool b = file == null; //there will be false
return RedirectToAction("Index");
}
// /Test/Wonder
[HttpGet]
public ActionResult Wonder()
{
return View();
}
[HttpPost]
public ActionResult Wonder(HttpPostedFile file)
{
bool b = file == null; //there will be TRUE!
return RedirectToAction("Wonder");
}
}
У меня похожие взгляды на мои действия.
Индекс действия:
<h2>Index</h2>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit" />
</form>
Чудо-действие:
<h2>It's wonder!</h2>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit" />
</form>
Почему первая форма (индекс) передает правильный файл контроллеру, а вторая форма (Wonder) передает ноль контроллеру?