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
|
Was trying to use "UpdateModel" using the Lightspeed MVC binder and following a NerdDinner example. It appears that this doesn't work for edits. It always returns a new entity rather than updating a passed entity. Is this an oversight or am I just doing something incorrectly? The examples only have a create occurring so there is nothing to go off of. Here's my very simple edit method: // // POST: /Dinners/Edit/2[AcceptVerbs(HttpVerbs.Post)]public ActionResult Edit(int id, FormCollection formValues){ Role role = RoleService.Load(id);if (ModelState.IsValid){ UpdateModel(role); RoleService.Update(role); RoleService.SaveChanges(); } return View(role);} |
|
|
Well, I solved this for myself by altering the source code of the EntityModelBinder class. Haven't tried a create yet, so hopefully this doesn't break that. If it does, I'll update. Method I updated was BindModel. Original: public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext){ if (!typeof(Entity).IsAssignableFrom(bindingContext.ModelType)) return null; Entity entity = (Entity)Activator.CreateInstance(bindingContext.ModelType);Updated: public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext){ if (!typeof(Entity).IsAssignableFrom(bindingContext.ModelType)) return null; var entity = (Entity)(bindingContext.Model ?? Activator.CreateInstance(bindingContext.ModelType)); If anybody notices a problem here, please let me know!Thanks, Eric
|
|