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 ...
随机推荐
- Centos6与Centos7的区别
前言 centos7与6之间最大的差别就是初始化技术的不同,7采用的初始化技术是Systemd,并行的运行方式,除了这一点之外,服务启动.开机启动文件.网络命令方面等等,都说6有所不同.让我们先来了解 ...
- vs 2015
基于应用要求和要使用的语言选择所需工具. Xamarin for Visual Studio:针对所有设备的 C# 中的常用基本代码 Apache Cordova with Visual Studio ...
- Oracle性能优化之oracle里表、索引、列的统计信息
一.表的统计信息 表的统计信息用于描述表的详细信息,包括记录数(num_rows).表块的数量(blocks).平均行长度(avg_row_len)等典型维度.这些维度可以通过数据字典表DBA_TAB ...
- 介绍一种android的裸刷机方法(fastboot刷机实质)
fastboot刷机的前提是你的开发板uboot良好并能正常启动进入fastboot模式,你的开发版的nand分区已存在.对于Android的uboot而言, 已经实现了fastboot命令,当你 ...
- 前端基础(JavaScript)2
3.2 Array对象 3.2.1 数组创建 创建数组的三种方式: 创建方式1: var arrname = [元素0,元素1,….]; // var arr=[1,2,3]; 创建方式2: var ...
- eclipse恢复默认布局
eclipse恢复默认布局 Window (->Perspective ->) Reset Perspective
- SQL Server与Oracle对表添加列的不同点
逛了博客园两年有余,不知道该发表些什么.要么觉得自己太菜,要么觉得要发的内容都可以搜索到,发表了还颇有抄袭味道.想想后都不得了之了. 搞了开发快一年了,有时候零零碎碎的东西需要整理一下,梳理后才能做到 ...
- 20155207 2016-2017-2 《Java程序设计》第八周学习总结
20155207 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 第15章 通用API 15.1 日志 15.1.1 日志API简介 java.util.lo ...
- Java面向对象---重写(Override)与重载(Overload)
一.重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变.即外壳不变,核心重写! 重写的好处在于子类可以根据需要,定义特定于自己的行为. 也就是说 ...
- nginx重启 failed (98: Address already in use)
启动nginx服务,无法正常启动,一查log日志,发现如题错误信息. 问题描述:地址已被使用.可能nginx服务卡死了,导致端口占用,出现此错误. 查看端口 netstat -ntpl 杀掉进程 ...


