简体   繁体   English

C# ASP.NET:使用验证显示错误消息

[英]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:这是我的User.cs model class 中显示错误的示例:

[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?)错误 CS0246:找不到类型或命名空间名称“ErrorResponse”(您是否缺少 using 指令或程序集引用?)

MinLength doesn't have a ErrorResponse property. MinLength没有ErrorResponse属性。 I see ErrorMessage property instead.我看到的ErrorMessage属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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