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. [SQL] 让特定的数据 排在最前

    MYSQL目前常用的两种方法,如下: 让值为"张三" 的数据排在最前. -- 方法一 end asc -- 方法二 select * from tableName where co ...

  2. Qt::浅谈信号槽连接,参数在多线程中的使用

    Qt的信号槽有五种连接方式定义在enum Qt::ConnectionType,下面简单介绍 Qt::AutoConnection:自动判断连接方式,如果信号发送对象和执行槽对象在同一线程,那么等于Q ...

  3. Python开发【Tornado】:异步Web服务(二)

    真正的 Tornado 异步非阻塞 前言: 其中 Tornado 的定义是 Web 框架和异步网络库,其中他具备有异步非阻塞能力,能解决他两个框架请求阻塞的问题,在需要并发能力时候就应该使用 Torn ...

  4. php版本管理工具composer安装及使用

    类似于web前端有gulp,webpack,grunt.php也有专门的包安装管理和安装工具,即composer. composer官网:https://getcomposer.org      中文 ...

  5. 【调研与分析】标杆学习、知识管理和竞争情报的关系——From Team

    注: 1)红色实线箭头表示可以直接使用:例如竞争情报业务输出产品之一的标杆文档可以直接作为公司标杆学习中外部标杆的资料: 2)蓝色虚线箭头表示转化后使用或者间接利用的关系:例如专题调研可以帮助建立内部 ...

  6. 使用 Nginx 提升网站访问速度

    使用 Nginx 提升网站访问速度 http://www.ibm.com/developerworks/cn/web/wa-lo-nginx/ Nginx 简介 Nginx ("engine ...

  7. 基于 Spark 的文本情感分析

    转载自:https://www.ibm.com/developerworks/cn/cognitive/library/cc-1606-spark-seniment-analysis/index.ht ...

  8. openSession()与getCurrentSession()的区别

    getCurrentSession创建的session会和绑定到当前线程,而openSession不会. getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSes ...

  9. HDU 1879 继续畅通工程(Prim||Kruscal模板题)

    原题链接 Prim(点归并) //异或运算:相同为假,不同为真 #include<cstdio> #include<algorithm> #define maxn 105 us ...

  10. [翻译] Rails::Railtie

    原文:http://api.rubyonrails.org/classes/Rails/Railtie.html Railtie 是 Rails  框架的核心,提供几个钩子来扩展或修改 Rails 的 ...