using System.Web.Mvc; namespace Kreta.Web.ModelBinder.Mvc { public class StringTrimModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); var attemptedValue = value?.AttemptedValue; return string.IsNullOrWhiteSpace(attemptedValue) ? null : attemptedValue.Trim(); } } }