MVC DateTime binding with incorrect date format

I’ve just found the answer to this with some more exhaustive googling: Melvyn Harbour has a thorough explanation of why MVC works with dates the way it does, and how you can override this if necessary: http://weblogs.asp.net/melvynharbour/archive/2008/11/21/mvc-modelbinder-and-localization.aspx When looking for the value to parse, the framework looks in a specific order namely: RouteData (not shown … Read more

Best way to trim strings after data entry. Should I create a custom model binder?

public class TrimModelBinder : DefaultModelBinder { protected override void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor, object value) { if (propertyDescriptor.PropertyType == typeof(string)) { var stringValue = (string)value; if (!string.IsNullOrWhiteSpace(stringValue)) { value = stringValue.Trim(); } else { value = null; } } base.SetProperty(controllerContext, bindingContext, propertyDescriptor, value); } } How about this code? ModelBinders.Binders.DefaultBinder = new TrimModelBinder(); … Read more