String Trim Binder

Trims all model string types after postback to clear out any whitespace at the start or end of fields.

To prevent a field from being trimmed use the [NoTrim] attribute.

Example

Program.cs
builder.Services.AddControllersWithViews(options =>
{
options.ModelBinderProviders.Insert(0, new ShareItModelBinderProvider());
});

To also trim Json strings

Program.cs
builder.Services.AddControllersWithViews(options =>
{
options.ModelBinderProviders.Insert(0, new ShareItModelBinderProvider());
})
.AddJsonOptions(opt =>
{
options.JsonSerializerOptions.Converters.Add(new StringTrimmerJsonConverter());
});