Specifies the numeric range constraints for the value of a data field.
public ref class RangeAttribute : System::ComponentModel::DataAnnotations::ValidationAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public class RangeAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)]
public class RangeAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)>]
type RangeAttribute = class
inherit ValidationAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)>]
type RangeAttribute = class
inherit ValidationAttribute
Public Class RangeAttribute
Inherits ValidationAttribute
The following example shows how to use the RangeAttribute to customize formatting for a data field. The example performs the following steps:
Implements a metadata partial class and the associated metadata class.
In the associated metadata class, it applies the RangeAttribute attribute to obtain the following results:
Apply the attribute to a data field of type integer.
Apply the attribute to an integer data field and define a custom validation error message.
Apply the attribute to a DateTime
data field and define a custom validation error message.
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
[MetadataType(typeof(ProductMetaData))]
public partial class Product
{
}
public class ProductMetaData
{
[Range(10, 1000,
ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public object Weight;
[Range(300, 3000)]
public object ListPrice;
[Range(typeof(DateTime), "1/2/2004", "3/4/2004",
ErrorMessage = "Value for {0} must be between {1} and {2}")]
public object SellEndDate;
}
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
Imports System.ComponentModel
<MetadataType(GetType(ProductMetaData))> _
Partial Public Class Product
End Class
Public Class ProductMetaData
<Range(10, 1000, _
ErrorMessage:="Value for {0} must be between {1} and {2}.")> _
Public Weight As Object
<Range(300, 3000)> _
Public ListPrice As Object
<Range(GetType(DateTime), "1/2/2004", "3/4/2004", _
ErrorMessage:="Value for {0} must be between {1} and {2}")> _
Public SellEndDate As Object
End Class
To compile the example, you need the following:
Microsoft Visual Studio 2008 Service Pack 1 or Visual Web Developer 2008 Express Edition SP1.
A data-driven Web site. This enables you to create a data context for the database and the class that contains the data field to customize. For more information, see Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding
.
When you apply this attribute to a data field, you must follow the guidelines for how to use validation attributes. For more information, see ASP.NET Dynamic Data Guidelines.
Constructors Properties Methods Explicit Interface Implementations _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)Maps a set of names to a corresponding set of dispatch identifiers.
(Inherited from Attribute) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)Retrieves the type information for an object, which can be used to get the type information for an interface.
(Inherited from Attribute) _Attribute.GetTypeInfoCount(UInt32)Retrieves the number of type information interfaces that an object provides (either 0 or 1).
(Inherited from Attribute) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)Provides access to properties and methods exposed by an object.
(Inherited from Attribute)RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4