Что не так с этим:
View
@model GestionWeb.DAL.Client
@using (Html.BeginForm("Index", "Config", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.LabelFor(model => model.TimeZone)
@Html.EditorFor(model => model.TimeZone)
@Html.ValidationMessageFor(model => model.TimeZone)
@Html.HiddenFor(model => model.ClientId)
@Html.LabelFor(model => model.Logo)
<input type="file" name="Logo" id="Logo" />
@Html.ValidationMessageFor(model => model.Logo)
<input type="submit" value="Upload" />
}
Контроллер:
[HttpPost]
public ActionResult Index(Client client)
{
if (ModelState.IsValid)
{
if (Request.Files[0].ContentLength > 0)
{
HttpPostedFileBase file = Request.Files[0];
string filePath = Path.Combine(HttpContext.Server.MapPath("/Upload/"), Path.GetFileName(file.FileName));
file.SaveAs(filePath);
client.Logo = file.FileName;
}
db.Client.Attach(client);
UpdateModel<Client>(client);
//db.ObjectStateManager.ChangeObjectState(client, EntityState.Modified);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(client);
}
Я могу написать файл, но имя файла не сохраняется в базе данных, я не получаю ошибок, я могу обновить поле TimeZone (и многие другие).
Что я делаю не так? Я не могу понять !!!
Спасибо