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
|
When using strongly type views with ASP.NET MVC the primary key is not being mapped to the object being passed to the controller action. To get around this I read the Id from the form and pass both (Id and object) to the update method in my repository. The Update method reads the object from the database using the Id and then update that object with the values from the form. Call SaveChanges and all is good. Is there a better method of updating my objects than what is shown below? // Controller action - bare bones code, no fluff
|
|
|
Hi 37Stars :) What you are currently doing is the manual way of doing this, to automate this you want to explicitely load an existing object from the repository and update it as a single model binding operation you could look at creating a custom model binder and then associate it with each of your entity types (and load based on the Id field involved). However make sure this is going to fit the way the application is used - e.g. you are performing a generic mapping so the expectation would be that you are allowing ALL fields to be updated on the calling form. Also any security related checks would need to be done prior to the model binding - e.g. as part of an action filter. For an example of a custom model binder, have a look at the model binder from the community code project: https://code.mindscape.co.nz/repos/LightSpeed/Mvc/Trunk/Src/Mindscape.LightSpeed.Mvc/Binding/EntityModelBinder.cs Jeremy |
|