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 中)


语法 
[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, 
    AllowMultiple = false)]
public class RequiredAttribute : ValidationAttribute

 

构造函数
 
 
 名称说明
System_CAPS_pubmethodRequiredAttribute()

初始化 RequiredAttribute 类的新实例。

属性
 
 
 名称说明
System_CAPS_pubpropertyAllowEmptyStrings

获取或设置一个值,该值指示是否允许空字符串。

System_CAPS_pubpropertyErrorMessage

获取或设置一条在验证失败的情况下与验证控件关联的错误消息。(从ValidationAttribute 继承。)

System_CAPS_pubpropertyErrorMessageResourceName

获取或设置错误消息资源的名称,在验证失败的情况下,要使用该名称来查找 ErrorMessageResourceType 属性值。(从 ValidationAttribute 继承。)

System_CAPS_pubpropertyErrorMessageResourceType

获取或设置在验证失败的情况下用于查找错误消息的资源类型。(从ValidationAttribute 继承。)

System_CAPS_protpropertyErrorMessageString

获取本地化的验证错误消息。(从 ValidationAttribute 继承。)

System_CAPS_pubpropertyRequiresValidationContext

获取指示特性是否要求验证上下文的值。(从 ValidationAttribute 继承。)

System_CAPS_pubpropertyTypeId

当在派生类中实现时,获取该 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;

}

 

 

转载于:https://www.cnblogs.com/CandiceW/p/4938673.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值