Introduction
In this blog we will see how range data annotation attribute works in MVC.
Step 1: Create asp.net web application

Choose mvc template

Setup entity framework


Employee.cs
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- namespace RangeAttributeDataAnnotationMVC.Models
- {
- [MetadataType(typeof(EmployeeMetaData))]
- public partial class Employee
- {
- }
- public class EmployeeMetaData
- {
- [Range(18, 56, ErrorMessage="Age Must be between 18 to 56")]
- public string Age { get; set; }
- }
- }
Output of the application looks like this

Summary
In this blog we have seen how range data annotation works in MVC. Happy coding.

Santhakumar MunuswamyPosted May 12, 2015, 12:35 AM
Nice