This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I'm new to LightSpeed, coming from Entity Framework. I have an MVC 3 app I'm converting from EF to LS version 4. I've followed the instructions in the user guide for implementing the LightSpeedEntityModelBinder in Global.asax.cs, but it's not working. In EF I would do this and the record would be updated: private Entities db = new Entities(); [HttpPost] public ActionResult SaveArticle(Article entity) { entity.Content = HttpUtility.HtmlDecode(sitePage.Content); entity.ModifyBy = User.Identity.Name; entity.ModifyDate = DateTime.Now; db.SaveChanges(); return RedirectToAction("Articles"); } With the LS version, the record is not being updated [HttpPost] public ActionResult EditArticle(Article entity) { var entity = UnitOfWork.Articless.Single(m => m.Id == entity.Id); entity.Content = HttpUtility.HtmlDecode(sitePage.Content); entity.ModifyBy = User.Identity.Name; entity.ModifyDate = DateTime.Now; UnitOfWork.SaveChanges(); return RedirectToAction("Articles"); } Is there something I am missing when using the LightSpeedEntityModelBinder? Thanks, James |
|
|
In your code you are re-assigning the entity to UnitOfWork.Articless.Single(m => m.Id == entity.Id) which blows away any unbound data which the model binder will have assigned to the entity instance so presumably what you are finding is you are missing all other data that may have been posted on the form. What does your route look like for making the update? Typically we use UpdateModel for unbinding the entity in the method itself so we can load and update existing object. An example would be to define a route like:
You can then have the action defined as:
Hope that helps!
|
|
|
Hi Jeremy, I tried what you suggested, but get the following error:
I'm still passing in the same Article and getting the Id from that. [HttpPost] public ActionResult EditArticle(Article entity) { var id = entity.Id; var article = UnitOfWork.Articles.Single(m => m.Id == id); UpdateModel(entity); //this is where it breaks return RedirectToAction("Sundays"); } Thanks, James |
|
|
My bad. I had commented out the following in Global.asax.cs
It seems to be working. I will post back with results. Thanks James Just checked and it's working like a champ. James |
|