public ActionResult Edit(int id) { var blog = repository.Find(id); if (blog == null) { return(NotFound()); } var model = new EditBlogsViewModel { Id = blog.ID, Title = blog.Title, ImageUrl = blog.Image, Description = blog.Description, Body = blog.Body }; return(View(model)); }
public ActionResult Edit(int id, EditBlogsViewModel model) { try { string FileName = UploadFile(model.File, model.ImageUrl); if (ModelState.IsValid) { var blog = new Blog { Title = model.Title, Image = FileName, Description = model.Description, Body = model.Body }; repository.Update(model.Id, blog); return(RedirectToAction("index")); } return(View(model)); } catch { return(View()); } }