I have Dropdownlist for country and state when i select country it give me states name according to country but i have to save the selected value in database but i dont know how to do that Please help.
My Controller
public ActionResult Index()
{
// List<OrbatTable> CountryList = db.OrbatTables.ToList();
List<OrbatTable> CountryList = db.OrbatTables.DistinctBy(x => x.CityName).ToList();
ViewBag.CountryList = new SelectList(CountryList, "CityName", "CityName");
return View();
}
public JsonResult GetStateList(String CityName)
{
db.Configuration.ProxyCreationEnabled = false;
List<OrbatTable> StateList = db.OrbatTables.Distinct().Where(x => x.CityName== CityName).Distinct().ToList();
return Json(StateList.Distinct(), JsonRequestBehavior.AllowGet);
}
My View
<div class="container">
<div class="form-group">
@if (ViewBag.CountryList != null)
{
@Html.DropDownListFor(model => model.CityName, ViewBag.CountryList as SelectList , "--Select City", new { @class = "form-control" })
}
</div>
<div class="form-group">
@Html.DropDownListFor(model => model.UnitName, new SelectList(""), "--Select Unit", new { @class = "form-control" })
</div>
</div>