Export (0) Print
Expand All

UIHintAttribute.UIHint Property

Gets or sets the name of the field template to use to display the data field.

Namespace:  System.ComponentModel.DataAnnotations
Assemblies:   System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)
  System.ComponentModel.Annotations (in System.ComponentModel.Annotations.dll)

public string UIHint { get; }

Property Value

Type: System.String
The name of the field template that displays the data field.

ASP.NET Dynamic Data provides field templates and page templates for rendering data fields in a data model. Field templates are user controls (.ascx files) that are mapped to data fields in the model. You can modify the default user controls that Dynamic Data provides, or you can create a custom user controls to use as field template. If you create a custom user control, you use the UIHint property on a property so that the property is rendered using the custom user control. The UIHint property specifies which field template to use when a specific column is rendered. The UIHint property can point to one of the templates provided in Dynamic Data or to a custom template. For example, you can create a custom field template named RedText_Edit.ascx, and then use the UIHint property to specify that the RedText_Edit.ascx control should be used to render a specified data field instead of the default Text_Edit.ascx template that is provided in Dynamic Data.

The following example shows how to specify that the UnitsInStock column in a database will be rendered by using the specified custom field template.

using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;

[MetadataType(typeof(ProductMetadata))]
public partial class Product 
{

}

public partial class ProductMetadata
{
    [UIHint("UnitsInStock")]
    [Range(100, 10000, 
    ErrorMessage = "Units in stock should be between {1} and {2}.")]
    public object UnitsInStock;

}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft