
in image above show what i need
I have three drop down list Country,City,District
three drop down list cascade each other
meaning select country fill City and select City fill District in edit or create both
in edit view i can get value selected previous for country and city for employee i need to edit
but District cannot get selected value for employee i need to edit
- in Edit view (get)
- @model WebCourse.Models.Customemployee2
- @{
- Layout = null;
- }
- "viewport" content="width=device-width" />
-
Edit -
- @using (Html.BeginForm())
- {
- "hidden" value="@ViewBag.Cityid" id="cityidhidden" />
- "hidden" value="@ViewBag.dist" id="disthidden" />
- Name:@Html.TextBoxFor(a => a.Name)
- Country:@Html.DropDownList("CountryId")
- City: name="CityId">
- District: name="DistrictId">
- "submit" />
- }
- in Edit function in controller empcourse
- public class empcourseController : Controller
- {
- mycourseEntities db = new mycourseEntities();
- // GET: empcourse
- public ActionResult Edit(int id)
- {
- Employee old = db.Employees.Find(id);
- if (old != null)
- {
- // country and city working
- //district not working
- int countryid = old.Destrict.City.Country.Id;
- var vm = new Customemployee2();
- vm.Name = old.Name;
- ViewBag.CountryId = new SelectList(db.Countries.ToList(), "Id", "CountryName",countryid);
- ViewBag.Cityid = old.Destrict.City.Id;
- ViewBag.dist = old.DistrictId;
- return View(vm);
- }
- //getcitybyid retrieve city it call in ajax in jquery and it working
- public JsonResult getcitybyid(int id)
- {
- db.Configuration.ProxyCreationEnabled = false;
- return Json(db.Cities.Where(a => a.CountryId == id), JsonRequestBehavior.AllowGet);
- }
- //getdistrictbyid retrieve district it call in ajax in jquery and it working
- public JsonResult getdistrictbyid(int id)
- {
- db.Configuration.ProxyCreationEnabled = false;
- return Json(db.Destricts.Where(a => a.CityId == id), JsonRequestBehavior.AllowGet);
- }
- }
- in model Customemployee2
- public class Customemployee2
- {
- public string Name { get; set; }
- public int DistrictId { get; set; }
- }
- }
Midhun TpPosted Aug 28, 2016, 10:37 AM
ahmed salahPosted Aug 28, 2016, 10:31 AM
Midhun TpPosted Aug 28, 2016, 9:34 AM
ahmed salahPosted Aug 28, 2016, 9:34 AM
ahmed salahPosted Aug 28, 2016, 9:19 AM
Midhun TpPosted Aug 28, 2016, 9:11 AM