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 ...
随机推荐
- 徐州网络赛A-Hard To Prepare【dp】【位运算】【快速幂】
After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a ...
- 全角半角符号引发的Entity Framework奇遇记
SQL Server的SQL查询不区分大小写,而LINQ查询区分大小写,所以在写LINQ代码时需要注意的是——如果这段LINQ代码将会被Entity Framework解析为SQL语句(LINQ to ...
- android使用library
http://www.vogella.com/tutorials/AndroidLibraryProjects/article.html 介绍support lib使用 http://de ...
- square-and-multiply algorithm
https://en.wikipedia.org/wiki/Square-and-multiply_algorithm
- UA-* headers
HTTP The Definitive Guide Request headers are headers that make sense only in a request message. The ...
- ManyToMany参数(through,db_constraint)
through : 指定自己写好的第三张表,我们可以给第三张表添加字段了(告诉Django不用建第三张表了,我们都给他配好了) class Book(models.Model): name=model ...
- 详谈LABJS按需动态加载js文件
为了提高页面的打开和加载速度,我们经常把JS文件放在页面的尾部,但是有些JS必须放在页面前面,这样就会增加页面的加载时间:于是出现了按需动态加载的概念,这个概念就是当页面需要用到这个JS文件或者CSS ...
- python之celery队列模块
一.celery队列简介 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celery. 1 ...
- java之对象适配器
对象的适配器模式 与类的适配器模式一样,对象的适配器模式把被适配的类的API转换成目标类的API,与类的适配器模式不同的是,对象的适配器模式不是使用继承关系连接到Adaptee类,而是使用委派关系连接 ...
- VS异常--未找到与约束 ContractName Microsoft.VisualStudio.Language.Intellisense.IGlyphService RequiredTypeIdentity
早上打开项目的时候突然遇到这么个错误: ======================= 未找到与约束 ContractName Microsoft.VisualStudio.Language.Inte ...


