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. Oracle性能优化之表压缩及并行提高效率的测试

    1.制作测试表 create table t1 as select * from FW_T_GTXLOG insert into t1 select * from t1; create table t ...

  2. 【Maven学习】Nexus OSS私服仓库的安装和配置

    背景 公司的代码依赖是通过Maven进行管理的,而Maven的私库我们使用的是Nexus,目前使用的版本是Nexus Repository Manager OSS 2.12.1. 但是由于之前我们搭建 ...

  3. Day03 javascript详解

    day03 js 详解 JavaScript的基础 JavaScript的变量 JavaScript的数据类型 JavaScript的语句 JavaScript的数组 JavaScript的函数 Ja ...

  4. 如何编写一个python项目

    https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001397616003925a ...

  5. ARM上电启动及Uboot代码分析

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qianlong4526888/article/details/27698707 注意:由于文档是去年 ...

  6. JS中手动触发事件的方法

    如果大家将一张网页看成一个form的话,大致上就成了一个web form的模型.在win form 下要想手动触发某一个对象的事件是很简单的,只要发送一条消息即可达成.(PostMessage) 但是 ...

  7. 【Lua】面向对象编程(二)

      多重继承: module(...,package.seeall) local function search(k,plist) ,#plist do local v=plist[i][k] if ...

  8. Preview all adidas NMD Singapore colorways just below

    A week ago, we've got a glimpse into adidas NMD Singapore for the future using their Tubular line. O ...

  9. Rails的HashWithIndifferentAccess

    ruby 2.0 引入了keyword arguments,方法的参数可以这么声明 def foo(bar: 'default') puts bar end foo # => 'default' ...

  10. sql server中的怎么把数值型转换为字符串

    ①select cast(字段 as varchar) from 表名 ②select convert(varchar(50),字段) from 表名