kreta/KretaWeb/ModelBinder/Mvc/StringTrimModelBinder.cs
2024-03-13 00:33:46 +01:00

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();
}
}
}