.cs
public ActionResult Index()
{
List<City> citys = new List<City>();
City city = new City();
city.CityId = 1;
city.Name = "Batman";
citys.Add(city);
SelectList selectListCity = new SelectList(citys, "CityId", "Name");
ViewBag.dropdownCity = selectListCity;
return View();
}
}
public class City
{
public int CityId { get; set; }
public string Name { get; set; }
}
. cshtml
@using (Html.BeginForm())
{
@Html.DropDownList("CityId", (SelectList)ViewBag.dropdownCity, "Seçiniz", new { @class = "form-control dropdown" })
}
Hiç yorum yok:
Yorum Gönder