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;
}
若要编译该示例,您需要以下各项:
-
Microsoft Visual Studio 2008 Service Pack 1 或 Visual Web Developer 2008 速成版 SP1。
-
数据驱动的网站。这允许您为数据库创建一个数据上下文,并允许您创建包含要自定义的数据字段的类。有关更多信息,请参见Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding。