Skip to content

AllowedValuesAttribute Class

A validation attribute that restricts a string (or string-collection) value to a fixed set, matched exactly. An absent value passes: whether a member is required is a separate question, asked by a separate attribute, which is why the framework's own AllowedValues cannot stand in for this one - it refuses null. Shared by the MVC and Minimal API OIDC server adapters, whose source generators emit it onto a generated model whenever the corresponding core property carries the declarative AllowedValues marker.

C#
public class AllowedValuesAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute

Inheritance System.ObjectSystem.AttributeSystem.ComponentModel.DataAnnotations.ValidationAttribute → AllowedValuesAttribute

Constructors

AllowedValuesAttribute(string[]) Constructor

A validation attribute that restricts a string (or string-collection) value to a fixed set, matched exactly. An absent value passes: whether a member is required is a separate question, asked by a separate attribute, which is why the framework's own AllowedValues cannot stand in for this one - it refuses null. Shared by the MVC and Minimal API OIDC server adapters, whose source generators emit it onto a generated model whenever the corresponding core property carries the declarative AllowedValues marker.

C#
public AllowedValuesAttribute(params string[] allowedValues);

Parameters

allowedValues System.String[]