Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add back the implicit [Required] for value types #2407

Closed
@rynowak

Description

@rynowak

MVC 5 had a behavior where a value-type was implicitly defined with ModelMetadata.IsRequired == true - additionally when a property had ModelMetadata.IsRequired == true then a [Required] attribute was implicitly added as a validator.

Since this behavior is applied to value types, the only observable effect is on the HTML generation of data-* attributes for value type properties. (ModelMetadata also contains the setting ModelMetadata.IsBindingRequired which effects server-side validation)

We've currently restored the behavior of setting ModelMetadata.IsRequired == true by-default for value types, but we need to add back the validator in the DataAnnotationsModelValidatorProvider and add tests to verify the HTML generation.

Doing this will also require removing the behavior from MutableObjectModelBinder where a property with a required validator will behave the same as a property marked [BindRequired]. This will likely have some fallout for tests that rely on the non-MVC5-compatible behavior. See: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/MutableObjectModelBinder.cs#L337

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions