validating radio buttons in a controller rather than the model requires a ValueProviderResult to be set explicitly

Catchy title to this little post! If you are validating a radio button and the user has not selected any radio buttons in the group then you will get an error if you use ModelState.AddModelError(“radiobuttonname”,”my error message”) unless you explicitly use ModelState.SetModelValue and pass in a ValueProvierResult as the model binder doesn’t like the null when it binds the view.
e.g.

ModelState.AddModelError(“gender”, “Please select male or female.”);
ValueProviderResult vpr = new ValueProviderResult(null, “”, null);
ModelState.SetModelValue(“gender”, vpr);

Updating selected fields with linq to sql

I have been writing a bunch of stuff in asp.net mvc of late and have been using linq to SQL to quickly pull together my DAL (although I have been using a repository pattern and castle Windsor to implement an IOC container which I picked up from the excellent pro asp.net mvc book). One of my entities is a profile object and, on editing, I only wanted to update the image field if the user uploaded a new image. After struggling to skip the field with linq I found I could select the old profile object from the data context and simply update the other fields declaratively if no Image is passed in the new profile object. I can’t help feeling there is a more elegant way of doing this but I have had to be pragmatic and implement this as it works. I’ll post the code shortly.

Asp.net mvc

Playing around with.net mvc. Quite cool architecture and gets over lots of the issues with classic .net like page bloat and trying to force statefulness on to an inherently stateless system. I like the tight integration that’s possible with jquery as well so I will adopt asap but I have to figure out how well it can run alongside classic .net whilst I rewrite existing components into mvc versions. Pattern based, test driven development – should be good.