Model Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace RAVDEVMVC.Models
{
public class Vehicles
{
public SelectList VehicleList { get; set; }
}
}
Controller Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RAVDEVMVC.Models;
namespace RAVDEVMVC.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
RAVEntities RE = new RAVEntities();
IList<vehicle> objVehicleList = (from data in RE.vehicles
select data).ToList();
vehicle objvehicle = new vehicle();
objvehicle.Vehicle1 = "Select";
objVehicleList.Insert(0, objvehicle);
SelectList objmodeldata = new SelectList(objVehicleList,"","Vehicle1",0);
Vehicles objVehicleModel = new Vehicles();
objVehicleModel.VehicleList = objmodeldata;
return View(objVehicleModel);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace RAVDEVMVC.Models
{
public class Vehicles
{
public SelectList VehicleList { get; set; }
}
}
Controller Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RAVDEVMVC.Models;
namespace RAVDEVMVC.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
RAVEntities RE = new RAVEntities();
IList<vehicle> objVehicleList = (from data in RE.vehicles
select data).ToList();
vehicle objvehicle = new vehicle();
objvehicle.Vehicle1 = "Select";
objVehicleList.Insert(0, objvehicle);
SelectList objmodeldata = new SelectList(objVehicleList,"","Vehicle1",0);
Vehicles objVehicleModel = new Vehicles();
objVehicleModel.VehicleList = objmodeldata;
return View(objVehicleModel);
}
}
}
View Code
@model RAVDEVMVC.Models.Vehicles
@Html.DropDownList("ddlVehicle",Model.VehicleList)