For the record, here's how I did it:
using System;
using System.Globalization;
using System.Web.Mvc;
namespace Utils.ModelBinders
{
public class CustomTimeSpanModelBinder : DefaultModelBinder
{
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor)
{
var form = controllerContext.HttpContext.Request.Form;
if (propertyDescriptor.PropertyType.Equals(typeof(TimeSpan?)))
{
var text = form[propertyDescriptor.Name];
DateTime value;
if (DateTime.TryParseExact(text, "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out value))
SetProperty(controllerContext,bindingContext,propertyDescriptor,value.TimeOfDay);
else if (DateTime.TryParseExact(text, "HH.mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out value))
SetProperty(controllerContext, bindingContext, propertyDescriptor, value.TimeOfDay);
else if (DateTime.TryParseExact(text, "HHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out value))
SetProperty(controllerContext, bindingContext, propertyDescriptor, value.TimeOfDay);
else if (DateTime.TryParseExact(text, "HH,mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out value))
SetProperty(controllerContext, bindingContext, propertyDescriptor, value.TimeOfDay);
else if (DateTime.TryParseExact(text, "HH", CultureInfo.InvariantCulture, DateTimeStyles.None, out value))
SetProperty(controllerContext, bindingContext, propertyDescriptor, value.TimeOfDay);
}
else
{
base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
}
}
}
}