Step1: Create new MVC Project.
Step2 . Create Database Table . In this example I created a table “categories” which have three fields
CategoryId int primarykey
CategoryName varchar(50)
IsSelected bool
Step 3: Create connectionstring in web.config.
Step 4: Create Model Class “Category.cs”
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace PopulateDropDown.Models
{
[Table("Categories")]
public class Category
{
[Key]
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public bool? IsSelected { get; set; }
}
}
Step 5: Create DataContext Class "DAL.cs"
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace PopulateDropDown.Models
{
public class DAL: DbContext
{
public DAL() : base("conn") { }
public DbSet
nice work plz provide some more examples