net6 - System.ComponentModel.DataAnnotations Attribute
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations; [MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
RangeAttribute 类
[Range(10, 1000,
ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public object Weight; [Range(300, 3000)]
public object ListPrice; [Range(typeof(DateTime), "1/2/2004", "3/4/2004",
ErrorMessage = "Value for {0} must be between {1} and {2}")]
public object SellEndDate; DataTypeAttribute 类
// Add type information.
[DataType(DataType.EmailAddress)]
public object EmailAddress; RegularExpressionAttribute 类
// Allow up to 40 uppercase and lowercase
// characters. Use custom error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public object FirstName; // Allow up to 40 uppercase and lowercase
// characters. Use standard error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
}
DisplayFormatAttribute类
public class ProductMetaData
{ // Applying DisplayFormatAttribute
// Display the text [Null] when the data field is empty.
// Also, convert empty string to null for storing.
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")]
public object Size; // Display currency data field in the format $1,345.50.
[DisplayFormat(DataFormatString="{0:C}")]
public object StandardCost; // Display date data field in the short format 11/12/08.
// Also, apply format in edit mode.
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]
public object SellStartDate;
}
DisplayColumnAttribute 类
[DisplayColumn("City", "PostalCode", false)]
public partial class Address
{
} [DisplayColumn("LastName")]
public partial class Customer
{
}
EnumDataTypeAttribute 类
public enum ReorderLevel
{
Zero = 0,
Five = 5,
Ten = 10,
Fifteen = 15,
Twenty = 20,
TwentyFive = 25,
Thirty = 30
} [MetadataType(typeof(ProductMD))]
public partial class Product
{
public class ProductMD
{
[EnumDataType(typeof(ReorderLevel))]
public object ReorderLevel { get; set; }
}
}
StringLengthAttribute 类
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{ } public class ProductMetadata
{ [ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
public object ThumbnailPhotoFileName; [ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The {0} value cannot exceed {1} characters. ")]
public object PhotoFileName; }
net6 - System.ComponentModel.DataAnnotations Attribute的更多相关文章
- 对System.ComponentModel.DataAnnotations 的学习应用
摘要 你还在为了验证一个Class对象中很多数据的有效性而写很多If条件判断吗?我也同样遇到这种问题,不过,最近学了一项新的方法,让我不在写很多if条件做判断,通过给属性标注特性来验证数据规则,从此再 ...
- System.ComponentModel.DataAnnotations 冲突
项目从原来的.NET Framework4.0 升级到 .NET Framework4.5 编译报错. 查找原因是: Entity Framework 与 .net4.5 的 System.Compo ...
- System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中
Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...
- System.ComponentModel.DataAnnotations.Schema 冲突
System.ComponentModel.DataAnnotations.Schema 冲突 Entity Framework 与 .net4.5 的 System.ComponentModel.D ...
- System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类
System.ComponentModel.DataAnnotations 命名空间提供定义 ASP.NET MVC 和 ASP.NET 数据控件的类的特性. RequiredAttribute 指定 ...
- 使用System.ComponentModel.DataAnnotations验证字段数据正确性
在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...
- 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突
比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...
- C# 特性 System.ComponentModel 命名空间属性方法大全,System.ComponentModel 命名空间的特性
目录: System.ComponentModel 特性命名空间与常用类 System.ComponentModel.DataAnnotations ComponentModel - Classes ...
- “CreateRiaClientFilesTask”任务意外失败。 未能加载文件程序集“System.ComponentModel.DataAnnot...
错误 77 “CreateRiaClientFilesTask”任务意外失败. System.Web.HttpException (0x80004005): 未能加载文件或程序集“System. ...
- 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。
本地win7 本地正常,服务器win2008r2,服务器报错! 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问. 拒绝访问. 说明: 执行当前 W ...
随机推荐
- tomcat不生成日志文件
1.不生成 catalina.out 将 /bin/catalina.sh 文件中的: if [ -z "$CATALINA_OUT" ] ; then CATALINA_OUT= ...
- ubuntu 安装SVN
s1: [sudo apt-get install subversion] s2:本地新建一个文件夹如SVN,在该文件夹下打开终端输入命令[svn co https://xxx/svn/xxx --u ...
- python安装及简单爬虫(爬取导师信息)
1.下载: 解释器(我下的是3.8.2版本):https://www.python.org/downloads/ pycharm(我下的是2019.3.3版本):https://www.jetbrai ...
- LAN8720 调试笔记
因为项目需要开始研究LAN8720,还没有仔细研究芯片手册就根据网上能找到的原理图画了第一版电路 调试整整花了我2天半,期间多亏硬汉哥的耐心解答.下面是我调试过程中遇到的一些坑 1.TPTX.TO ...
- 15. 测试环境部署-linux
抽奖项目部署文档: 1.抽奖项目使用python3开发,python版本3.x都可以 需要安装的python第三方模块 pip install django==1.9.0 这个一定要加版本号 pip ...
- 记maven打包加入外部jar后tomcat运行失败问题
环境:maven 3.8.0 .tomcat 8.5.30 因为项目需要额外的引用外部jar,需要打包到war中. 所以在pom中加入了 <webResources> <resour ...
- Python的入门学习Day 16~18——form”夜曲编程“
Day 16 Day 17 time:2021.8.14. 今天七夕.激动,喜悦.平静呼吸,嘻嘻~ 也许我也是天空.去看课程了,嗯.今天重点学习了循环的对立面--"跳出循环"的 ...
- 【虚拟机】虚拟机安装win10
VMware-workstation 16 pro 点击查看代码 密钥: ZF3R0-FHED2-M80TY-8QYGC-NPKYF YF390-0HF8P-M81RQ-2DXQE-M2UT6 ZF7 ...
- hex 函数
python的内置函数. 一.作用: 用于将十进制数改为十六进制数,并以字符串的形式表示. 二.语法: hex(number) # 其中number为十进制的整数. 三.返回值: 以字符串形式表示的 ...
- kali安装CloudKeyKiller-一款阿里云AK泄露工具
工具下载地址:https://github.com/UzJu/CloudKeyKiller 问题描述:ModuleNotFoundError: No module named 'aliyunsdkec ...