Hello,
I tried to make an attempt of a basic project Core 2 with just a model:
public class Bilance
{
[Key]
public int Id { get; set; }
[Required]
public decimal Amount{ get; set; } // (sql 18,2)
}
I used this Custom Model Binding to use the comma as decimal seperator but it doesn't work.
<div id="m_-8531784082358642913divtagdefaultwrapper" dir="ltr">I used this Custom Model Binding to use the comma as decimal seperator but it doesn't work:
public class InvariantDecimalModelBinderPro
{
public IModelBinder GetBinder(
{
if (context == null) throw new ArgumentNullException(nameof(
if (!context.Metadata.
{
return new InvariantDecimalModelBinder(
}
return null;
}
}
public class InvariantDecimalModelBinder : IModelBinder
{
private readonly SimpleTypeModelBinder _baseBinder;
public InvariantDecimalModelBinder(
{
_baseBinder = new SimpleTypeModelBinder(
}
public Task BindModelAsync(
{
if (bindingContext == null) throw new ArgumentNullException(nameof(
var valueProviderResult = bindingContext.ValueProvider.
if (valueProviderResult != ValueProviderResult.None)
{
bindingContext.ModelState.
var valueAsString = valueProviderResult.
// Use invariant culture
if (decimal.TryParse(
{
bindingContext.Result = ModelBindingResult.Success(
return Task.CompletedTask;
}
}
// If we haven't handled it, then we'll let the base SimpleTypeModelBinder handle it
return _baseBinder.BindModelAsync(
}
}
{
// ....
services.AddMvc(config =>
{
config.ModelBinderProviders.
});</div>
Works with a few numbers (123,456) with others no (11,50... 1520,77)
Could you help me?
Thanks