简体   繁体   中英

C# ASP.NET : show an error message using validations

I want to show validation errors when someone doesn't follow my validation rules (such as too few characters for a first name) or an error when they leave the field empty.

This is an example from my User.cs model class that is showing an error:

[Required(ErrorResponse= "Please do not leave first name field empty")]
[MinLength(4, ErrorResponse = "First name min length is 4")]
public string Firstname { get; set; }

The error I am getting:

Error CS0246: The type or namespace name 'ErrorResponse' could not be found (are you missing a using directive or an assembly reference?)

MinLength doesn't have a ErrorResponse property. I see ErrorMessage property instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM