-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimalModelBinderProvider.cs
More file actions
25 lines (23 loc) · 966 Bytes
/
DecimalModelBinderProvider.cs
File metadata and controls
25 lines (23 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace CourseNet.Web.Infrastructure.ModelBinders
{
public class DecimalModelBinderProvider : IModelBinderProvider
{
// ModelBinderProviderContext is a context object for creating an IModelBinder.
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
// If the context is null, throw an ArgumentNullException.
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// If the model type is decimal or decimal?, return a new DecimalModelBinder.
// The DecimalModelBinder is a custom model binder for decimal and decimal? types.
if (context.Metadata.ModelType == typeof(decimal) || context.Metadata.ModelType == typeof(decimal?))
{
return new DecimalModelBinder();
}
return null!;
}
}
}