I am trying to learn MVC & EF to move away from WebForms and ADO.NET. I am just throwing together my first trial site so see how it goes and have hit a stumbling block.
I am editing a record on the page and pressing save.I get no errors returned however the data is not updated.
The Article Model being updated
public class Article
{
[Key]
public int Id { get; set; }
public string Author { get; set; }
public string Title { get; set; }
public DateTime DateCreated { get; set; }
public string Body { get; set; }
public int Likes { get; set; }
public int Dislikes { get; set; }
public List<Comment> Comments { get; set; }
public string Tags { get; set; }
public int Category { get; set; }
}
The edit code on the Controller, the articleId is from the querystring.
[HttpPost]
public ActionResult Edit(int articleId, FormCollection collection)
{
var result = from i in db.Articles
where i.Id == articleId
select i;
if (TryUpdateModel(result))
{
db.SaveChanges();
return RedirectToAction("Index");
}
return View(result.First());
}
On debugging, the TryUpdateModel() returns true and calls the db.SaveChanges. No errors are returned. When being directed back to the Index method on the Controller, the article is showing unchanged.
Is it something glaringly obvious?
Many Thanks