Mid ASP.NET Core

Custom validation attributes?

Create custom rules by inheriting ValidationAttribute:

public class MustBeEvenAttribute : ValidationAttribute {

public override bool IsValid(object value) {

return (int)value % 2 == 0;

Use like:

[MustBeEven]

public int Number { get; set; }

More from ASP.NET Core Tutorial

All questions for this course