Create a class Dropdownlist like below
Try like this
using System.Collections.Generic;using System.Web.Mvc;
namespace EDaaS.Domain.Utilities
{
public static class DropDownList<T>
{
public static SelectList LoadItems(IList<T> collection, string value, string text)
{
return new SelectList(collection, value, text);
}
}
}
Your View
@Html.DropDownListFor(model => model.CityID, (IEnumerable<SelectListItem>)ViewBag.EmployeeList, "--Select--", new { @class = "select" })
Your ActionResult
ViewBag.EmployeeList =
Domain.Utilities.DropDownList<City>.LoadItems(db.City.ToList(), "CityID", "CityName");
Hope this helps