Я уже перепробовал все решения, которые нашел в StackOverflow, но они не работают для меня.Я также пробовал решение Tetsuya Yamamoto, но оно все равно всегда возвращает null
, когда я использую его с моделью.
Обновление
Когда я проверяю его, тогда мой тип файлавходные данные хранятся, но в проверяемом элементе его значение равно ""
В обоих случаях мой опубликованный файл выглядит так:
@using (Html.BeginForm("AddLocation", "MasterData", FormMethod.Post, new { encytype = "multipart/form-data"}))
{
<div class="file-upload">
<input type="file" name="postedFile" />
</div>
//passing model value when using it
}
без модели рабочего совершенства
public ActionResult AddLocation(HttpPostedFileBase file)
{
try
{
if (file != null) //Working Perfact
{
}
return View(model);
}
catch (Exception ex)
{
return View(model);
throw;
}
}
с моделью всегда повторного запуска null
public ActionResult AddLocation(LocationModel model, HttpPostedFileBase file)
{
try
{
if (ModelState.IsValid)
{
if (file != null) //Always return null when passing with model
{
}
}
return View(model);
}
catch (Exception ex)
{
return View(model);
throw;
}
}