System.ComponentModel.DataAnnotations 命名空间提供定义 ASP.NET MVC 和 ASP.NET 数据控件的类的特性。

RequiredAttribute

指定需要数据字段值。

https://msdn.microsoft.com/zh-cn/library/system.componentmodel.dataannotations.aspx

RequiredAttribute 类

 
 

指定需要数据字段值。

命名空间:   System.ComponentModel.DataAnnotations
程序集:  System.ComponentModel.DataAnnotations(System.ComponentModel.DataAnnotations.dll 中)

[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
AllowMultiple = false)]
public class RequiredAttribute : ValidationAttribute
  名称 说明
RequiredAttribute()

初始化 RequiredAttribute 类的新实例。

属性

 
 
  名称 说明
AllowEmptyStrings

获取或设置一个值,该值指示是否允许空字符串。

ErrorMessage

获取或设置一条在验证失败的情况下与验证控件关联的错误消息。(从ValidationAttribute 继承。)

ErrorMessageResourceName

获取或设置错误消息资源的名称,在验证失败的情况下,要使用该名称来查找 ErrorMessageResourceType 属性值。(从 ValidationAttribute 继承。)

ErrorMessageResourceType

获取或设置在验证失败的情况下用于查找错误消息的资源类型。(从ValidationAttribute 继承。)

ErrorMessageString

获取本地化的验证错误消息。(从 ValidationAttribute 继承。)

RequiresValidationContext

获取指示特性是否要求验证上下文的值。(从 ValidationAttribute 继承。)

TypeId

当在派生类中实现时,获取该 Attribute 的唯一标识符。(从 Attribute 继承。)

 
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
using System.Globalization; [MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{ } public class CustomerMetaData
{
// Require that the Title is not null.
// Use custom validation error.
[Required(ErrorMessage = "Title is required.")]
public object Title; // Require that the MiddleName is not null.
// Use standard validation error.
[Required()]
public object MiddleName; }

System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类的更多相关文章

  1. System.ComponentModel.DataAnnotations 冲突

    项目从原来的.NET Framework4.0 升级到 .NET Framework4.5 编译报错. 查找原因是: Entity Framework 与 .net4.5 的 System.Compo ...

  2. System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中

    Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...

  3. System.ComponentModel.DataAnnotations.Schema 冲突

    System.ComponentModel.DataAnnotations.Schema 冲突 Entity Framework 与 .net4.5 的 System.ComponentModel.D ...

  4. 使用System.ComponentModel.DataAnnotations验证字段数据正确性

    在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...

  5. 对System.ComponentModel.DataAnnotations 的学习应用

    摘要 你还在为了验证一个Class对象中很多数据的有效性而写很多If条件判断吗?我也同样遇到这种问题,不过,最近学了一项新的方法,让我不在写很多if条件做判断,通过给属性标注特性来验证数据规则,从此再 ...

  6. 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突

    比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...

  7. 网络编程基础——System.Net.Socket 命名空间及相关类的使用

    System.Net.Socket 命名空间主要提供制作 Socket 网络应用程序的相关类.(Socket 类.TcpClient 类.TcpListener 类 和 UdpClient 类) 1. ...

  8. 用 .NET Reflector 8 查看 System.Windows.Controls 命名空间下的类

    为了学习自定义控件,就想看看WPF基本元素的代码.使用到工具.NET Reflector. System.Windows.Controls 命名空间在PresentationFramework.dll ...

  9. C# 特性 System.ComponentModel 命名空间属性方法大全,System.ComponentModel 命名空间的特性

    目录: System.ComponentModel 特性命名空间与常用类 System.ComponentModel.DataAnnotations ComponentModel - Classes ...

随机推荐

  1. Chinese_remainder_theorem

    https://en.wikipedia.org/wiki/Chinese_remainder_theorem 中国剩余定理 https://en.wikipedia.org/wiki/RSA_(cr ...

  2. 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask

    参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...

  3. 聪明的打字员---poj1184(bfs)

    题目链接:http://poj.org/problem?id=1184 分析:首先可以发现有6*10^6种状态,比较多,不过搜索的时候可以去除一些无用的状态, 可以发现一个点的值(2-5)如果想要改变 ...

  4. Python开发【笔记】:如何在字典遍历中删除key值?

    数据遍历时不能犯傻系列 前言: 针对字典做一些操作时,有时会遇到下面的状况,列如我们需要把data中的key值根据replace中的映射关系进行替换(Caller替换为caller) data = { ...

  5. 通过IP获取对应所在地的地址

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wangshuxuncom/article/details/35988143         曾几何时 ...

  6. 【开发者笔记】C#连接mysql问题记录

    1.概述:C#在调用mysql.data.dll连接本地数据库时报错,连接远程Linux服务器上的mysql服务器正常 2.报错记录,当前连接字符串 <add key="dbStrin ...

  7. CentOS 7 集群使用NTP进行时间同步

    NTP时钟同步方式说明NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步: 直接同步 使用ntpdate命令进行同步,直接进行时间变更.如果服务器上存在一个12点运行的任务,当前服务器时 ...

  8. 2006 - MySQL server has gone away

    mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了. 造成这样的原因一般是s ...

  9. 转:CentOS设置程序开机自启动的方法

    转自:http://www.centos.bz/2011/09/centos-setup-process-startup-boot/ 1.把启动程序的命令添加到/etc/rc.d/rc.local文件 ...

  10. stringbuffer 和 stringbuilder区别

    stringbuffer  和  stringbuilder速度                 小于         线程安全           线程非安全 单线程操作大量数据用stringbui ...