Click here to Skip to main content
15,880,608 members
Articles / Web Development / ASP.NET

ASP.NET MVC Model Binding - Part 2

Rate me:
Please Sign up or sign in to vote.
4.55/5 (9 votes)
27 Mar 2011CPOL3 min read 60.2K   1K   27  
This article gives the reader detailed understanding on how ASP.NET MVC Model binding works.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace ModelBinding1.Models
{
    //[MetadataType (typeof(EmployeeMetadata)) ]
    public class Employee
    {
        [DisplayName("Employee ID")]
        [Required(ErrorMessage = "ID Required")]
        public int EmpId { get; set; }
        [DisplayName("Employee Name")]
        [Required]
        public string EmpName { get; set; }
        [DisplayName("Designation")]
        [Required]
        public string EmpDesignation { get; set; }
        [DisplayName("Department")]
        [Required]
        public string EmpDepartment { get; set; }
        [DisplayName("Salary")]
        [Required]
        public float EmpSalary { get; set; }
        
    }
    public class EmployeeSkills
    {
        [DisplayName("Employee ID")]
        [Required(ErrorMessage = "ID Required")]
        public int EmpId { get; set; }
        [DisplayName("Employee Skills")]
        public string[] Skills { get; set; }
    }
    


    public class EmployeeMetadata
    {
        [DisplayName("Employee ID")]
        [Required(ErrorMessage="ID Required")]
        public int EmpId { get; set; }
        [DisplayName("Employee Name")]
        [Required]
        public string EmpName { get; set; }
        [DisplayName("Designation")]
        [Required]
        public string EmpDesignation { get; set; }
        [DisplayName("Department")]
        [Required]
        public string EmpDepartment { get; set; }
        [DisplayName("Salary")]
        [Required]
        public float EmpSalary { get; set; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
I have around 9 years of experience in Microsoft technologies, .Net 2.0,3.5, Asp.net MVC developed small to medium scale products using Silverlight 2.0, Asp.net Ajax technologie and Javascript frameworks.

Comments and Discussions