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!
Clean Phone Numbers
I’ve been working with a lot of person type data recently at work and I’m using data from multiple sources. Not just two databases but two separate systems with similar and yet incompatible data. One of the biggest messes was the phone numbers. I need to convert a phone number from a completely un-normalized format to a very strict format. I’m no regular expression genius so thankfully a quick Google search produced a nice PHP method of doing pretty much exactly what I was looking for. (http://cnanney.com/journal/code/cleaning-phone-numbers-with-regex/) I took that method and re-wrote it in C# and tweaked it a little for my application. I’m sure this isn’t the absolute best way to do this but it works for me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | const string pattern = @"\D*\(?(\d{3})?\)?\D*(\d{3})\D*(\d{4})\D*(\d{1,8})?"; string num, ext; var matches = new Regex(pattern).Match(number).Groups; if (matches.Count > 0) { if (matches[3].Length > 0) { if (matches[1].Length > 0) { num = "(" + matches[1].Value + ") " + matches[2].Value + "-" + matches[3].Value; } else { num = matches[2].Value + "-" + matches[3].Value; } } else { num = null; } ext = matches[4].Length > 0 ? matches[4].Value : null; } else { num = null; ext = null; } |
2009: Year in Review
Well I guess it’s about time I write about what has happened in the last 12 months. This past year has been the biggest year of changes in my life thus far. Here is the rundown:
- Started January at IWU, my final semester of college, living off campus (since September 2008)
- February 25th I joined Twitter
- In February I began my job search
- February 16th I took and passed the Zend PHP 5 Certification
- In April I was hired by FORUM Credit Union
- April 25th I graduated from Indiana Wesleyan University with a B.S. in Computer Internet Development
- April 26th I moved to Indianapolis, IN
- April 29th I began my new job at FORUM
- May 21st I proposed to Katie Stipe, and she said YES!
- In August we had engagement photos taken
- June, July, August, September and October was a blur of wedding preparations
- October 17th I got married! (photos)
- In December we took a vacation to Disney in Florida (I hadn’t been there since I was 6)
It has been a great, full year. I’m very much looking forward to a slower yet just as fulfilling 2010.
You should follow me on twitter to get the latest from 2010.
11.16.09FORUM Solutions is hiring!
FORUM Solutions is looking for a senior level .NET developer to join our team.
You can look at our official blog post.
The official job posting is on FORUM’s openhire site.
If you’re interested I encourage you to submit your resume and contact us!
FORUM Solutions is currently looking for a senior level (5+ years) .NET developer.