restores the legacy behavior
This commit is contained in:
parent
61f2b79048
commit
2f7d5a4b2e
5 changed files with 175 additions and 152 deletions
45
Yavsc/CustomModelBinder.cs
Normal file
45
Yavsc/CustomModelBinder.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
public class MyDecimalModelBinder : IModelBinder
|
||||
{
|
||||
|
||||
public async Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
ValueProviderResult valueResult = bindingContext.ValueProvider
|
||||
.GetValue(bindingContext.ModelName);
|
||||
decimal actualValue ;
|
||||
|
||||
try {
|
||||
actualValue = Decimal.Parse(valueResult.FirstValue, System.Globalization.NumberStyles.AllowDecimalPoint);
|
||||
return await ModelBindingResult.SuccessAsync(bindingContext.ModelName,actualValue);
|
||||
}
|
||||
catch (Exception ) {
|
||||
}
|
||||
return await ModelBindingResult.FailedAsync(bindingContext.ModelName);
|
||||
}
|
||||
}
|
||||
|
||||
public class MyDateTimeModelBinder : IModelBinder
|
||||
{
|
||||
public async Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
ValueProviderResult valueResult = bindingContext.ValueProvider
|
||||
.GetValue(bindingContext.ModelName);
|
||||
DateTime actualValue ;
|
||||
ModelStateEntry modelState = new ModelStateEntry();
|
||||
// DateTime are sent in the french format
|
||||
if (DateTime.TryParse(valueResult.FirstValue,new CultureInfo("fr-FR"), DateTimeStyles.AllowInnerWhite, out actualValue))
|
||||
{
|
||||
return await ModelBindingResult.SuccessAsync(bindingContext.ModelName,actualValue);
|
||||
}
|
||||
|
||||
return await ModelBindingResult.FailedAsync(bindingContext.ModelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue