JsonDateTimeModelBinder¶
Custom IModelBinder that tolerantly binds DateTime values from either the ASP.NET JSON date wire format (/Date(ms)/) or a standard parseable string, never raising a binding error on unparseable input.
Purpose¶
- Custom
IModelBinderthat tolerantly bindsDateTimevalues from either the ASP.NET JSON date wire format (/Date(ms)/) or a standard parseable string, never raising a binding error on unparseable input.
Context¶
- Namespace:
SAIF.Web.Mvc.ModelBinders - Assembly/package:
SAIF.Framework.Web.Mvc (source-shipping NuGet package) - Kind: class
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| BindModel(ControllerContext, ModelBindingContext) | public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) |
Returns DateTime() default when no value is found, null when the raw value is null, parses the /Date(ms)/ epoch form when present, and falls back to DateTime.TryParse otherwise; see the "Bind a JSON date value" operation. |
Behavioral notes¶
- A parse failure returns
default(DateTime)rather than raising a model-state error (see BR-41).
Constraints and usage notes¶
- Must be registered explicitly (e.g. via
ModelBinders.Binders) for aDateTime-typed property to use this binder instead of the framework default.
Sources¶
src/Web.Mvc/ModelBinders/JsonDateTimeModelBinder.cs