Files
2020-03-06 16:07:06 +00:00

45 lines
1.4 KiB
C#

using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sarand.Core.Base;
namespace Sarand.OperationsMgr.Web.System
{
//=======================================================================
/// <summary>
/// Maps a browser request to a data object. Default class provides a base implementation of a model binder.
/// <para>Overridden to trim whitespace from input values.</para>
/// </summary>
public class OpnModelBinder : IModelBinder
{
//-------------------------------------------------------------------
// Construction.
public OpnModelBinder ()
{
}
//-------------------------------------------------------------------
public Task BindModelAsync (ModelBindingContext bindingContext)
{
// Ignore selected properties by name.
var modelName = bindingContext.ModelName;
if (modelName == "RetainAllWhiteSpace")
return Task.CompletedTask;
ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
if (valueProviderResult == ValueProviderResult.None)
return Task.CompletedTask;
// Trim text values.
bindingContext.Result = ModelBindingResult.Success(valueProviderResult.FirstValue.TrimAll());
return Task.CompletedTask;
}
//-------------------------------------------------------------------
}
//=======================================================================
}