SelectMethod in ASP.NET 4.5 Model binding

  • Home
  • Blog
  • SelectMethod in ASP.NET 4.5 Model binding

New version of ASP.NET provides lots of way of binding data to the data controls like Grid View, Repeater etc. You can now bind this controls with strong type. I have earlier written a blog post about How we can use Model binding with ASP.NET 4.5 and Visual Studio 2012. In asp.net 4.5, It is also possible to bind controls with SelectMethod attribute. This method specify the data that you want to bind with data controls like grid view and repeater controls. So what we are waiting for?? Let’s take an simple example. I have create a basic model class “Employee” like below.

public class Employee
{
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

This class contains three properties EmployeeId,FirstName and LastName. Now I have created one method to get a generic list of employee model like following.

public List GetEmployees()
{
    List employeeList = new List();
    for (int i = 1; i