csharp 验证数据-annotation.cs

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 验证数据-annotation.cs相关的知识,希望对你有一定的参考价值。

using System.ComponentModel.DataAnnotations;
namespace WebApplication1.Models
{
    public class Product
    {
        public int Id { get; set; }

        [Display(Name = "Product name")]
        [Required(ErrorMessage = "{0} is required")]
        [StringLength(250, MinimumLength = 2, ErrorMessage = "{0} must be from {2} to {1} characters")]
        public string Name { get; set; }

        [Display(Name = "Poduct price"), Required(ErrorMessage = "{0} is required")]
        public double Price { get; set; }

        [Display(Name = "Price description")]
        public string Description { get; set; }

        [Display(Name = "Product snippet")]
        [StringLength(250, ErrorMessage = "{0} is too long")]
        public string Snippet { get; set; }
    }
}

以上是关于csharp 验证数据-annotation.cs的主要内容,如果未能解决你的问题,请参考以下文章

csharp 自定义数据注释验证属性,用于验证数据是两个字符的美国州名缩写。

csharp 数据注释,验证

csharp 用于测试数据的验证属性晚于另一个

csharp 数据注释属性,用于验证字符串是否为有效的XML

csharp 键入模式身份验证

csharp 验证AD用户