What is wrong with this:
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" />
}
Controller:
[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);
}
I can write the file, but the file name is not saved to database, I'm not getting errors, I can update TimeZone field (and so many others).
What I'm doing wrong? I cannot figure out!!!
Thanks