04.30.10

QUOTE – Simplicity

You’re not going to need to handle N kinds of book loan, you’re going to handle at most two, so don’t write some complicated code to handle the general case. You’re not going to need three classes, one interface and two event types for your “please wait” animation because there’s only ever going to be one and it’s always going to be while printing. Just write a function with a callback and release – the simpler it is, the quicker we can write it today and the more easily we can modify it tomorrow.

- coderoom

| Posted in code | No Comments »
02.23.10

UpdateModel requires properties

I was working on a feature at work this week on a ASP MVC project. I was attempting to use UpdateModel to update an object retrieved from the database with values from the POST. If you aren’t familiar with it, ASP MVC has a “magic method” to map these POST values to an object. One simply needs to call

UpdateModel(myObjectFromDatabase);

and the new values will be changed on the object.

That is all fine and dandy unless it doesn’t work. I had checked everything. I could verify that the values were in the Request header. I could verify that UpdateModel was called and did not fail. The values simply were not updated.

I finally found the key (thanks to my supervisor). The object I was updating had a mix of auto-properties and fields. Apparently, UpdateModel will only update properties. A quick change from a field to an auto-property and everything worked as it should. Thanks Aaron!