System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类
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 中)
System.Attribute
System.ComponentModel.DataAnnotations.ValidationAttribute
System.ComponentModel.DataAnnotations.RequiredAttribute
[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 |
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 类的更多相关文章
- 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验证字段数据正确性
在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...
- 对System.ComponentModel.DataAnnotations 的学习应用
摘要 你还在为了验证一个Class对象中很多数据的有效性而写很多If条件判断吗?我也同样遇到这种问题,不过,最近学了一项新的方法,让我不在写很多if条件做判断,通过给属性标注特性来验证数据规则,从此再 ...
- 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突
比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...
- 网络编程基础——System.Net.Socket 命名空间及相关类的使用
System.Net.Socket 命名空间主要提供制作 Socket 网络应用程序的相关类.(Socket 类.TcpClient 类.TcpListener 类 和 UdpClient 类) 1. ...
- 用 .NET Reflector 8 查看 System.Windows.Controls 命名空间下的类
为了学习自定义控件,就想看看WPF基本元素的代码.使用到工具.NET Reflector. System.Windows.Controls 命名空间在PresentationFramework.dll ...
- C# 特性 System.ComponentModel 命名空间属性方法大全,System.ComponentModel 命名空间的特性
目录: System.ComponentModel 特性命名空间与常用类 System.ComponentModel.DataAnnotations ComponentModel - Classes ...
随机推荐
- Flask简介之简单应用
Flask 0.Flask简介 Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收ht ...
- Openstack(六)RabbitMQ集群
各组件通过消息发送与接收是实现组件之间的通信: 6.1安装RabbitMQ 6.1.1安装RabbitMQ # yum install rabbitmq-server –y # systemctl s ...
- 找回 linux root密码的几种方法
第1种方法: 1.在系统进入单用户状态,直接用passwd root去更改 2.用安装光盘引导系统,进行linux rescue状态,将原来/分区挂接上来,作法如下: Java代码 #> c ...
- java基础语法this关键字
未经允许,禁止转载!!!!!!!! this关键词在java里面很重要,想了解清楚this就必须对 类:对象:this:成员变量:方法:构造方法 都了解清楚. 一.使用this调用本类中的成员变量( ...
- 20155331 2016-2017-2 《Java程序设计》第8周学习总结
20155331 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 NIO与NIO2 NIO使用频道(channel)来衔接数据节点,对数据区的标记提供了cle ...
- 详细解析Linux /etc/passwd文件
本文转自:http://os.51cto.com/art/201003/187533.htm 在Linux /etc/passwd文件中每个用户都有一个对应的记录行,它记录了这个用户的一些基本属性.系 ...
- LoRa无线通信设计(一)原理
LoRa无线通信设计(一)原理 引言 1901年,古列尔默.马可尼把长波无线电信号从Cornwall(康沃尔,位于英国的西南部)跨过大西洋传送到3200公里之外的Newfoundland(加拿大的纽芬 ...
- INNODB锁(2)
在上一篇文章写了锁的基本概述以及行锁的三种形式,这一篇的主要内容如下: 一致性非锁定读 自增长与锁 外键和锁 一致性性非锁定读 一致性非锁定读是InnoDB通过多版本并发控制(MVCC,multi v ...
- mysql日期和JDBC查询出来的结果相差8小时
数据库时间:2017-11-08 16:30:00 查询出来: 2017-11-09 00:30:00 问题:数据库时区,和JDBC连接时区设置问题. set global time_zone = ' ...
- Android实践项目汇报
Android实践项目:推箱子 推箱子是一款来自日本的古老游戏,其设计目的是训练人的逻辑思维能力.游戏场景一般是设定在空间狭小的仓库中,要求把箱子摆放到指定位置.这就要求玩家巧妙的运用有限的空间和通道 ...


