A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.rangeattribute below:

RangeAttribute Class (System.ComponentModel.DataAnnotations) | Microsoft Learn

RangeAttribute Class Definition

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
Inheritance
Attributes
Examples

The following example shows how to use the RangeAttribute to customize formatting for a data field. The example performs the following steps:

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:

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