Add project files.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user