15 lines
496 B
C#
15 lines
496 B
C#
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();
|
|
}
|
|
}
|
|
}
|