
in image above it retrieve wrong city for district
when i need to edit for id 4 in table district as image
it give me wrong city
country name and district name is retrieve true
- edit view District
- @model WebCourse.Models.Destrict
- @{
- Layout = null;
- }
- "viewport" content="width=device-width" />
Edit - @using (Html.BeginForm())
- {
- CountryName:@Html.DropDownList("ctry")
- City: name="CityId">
- DistrictName:@Html.TextBoxFor(a => a.DistrictName)
- "submit" />
- }
- in district controller in edit (get)
- namespace WebCourse.Controllers
- {
- public class DistrictController : Controller
- {
- mycourseEntities db = new mycourseEntities();
- public ActionResult Edit(int id)
- {
- Destrict D = db.Destricts.Find(id);
- int ctryold = D.City.Country.Id;
- ViewBag.ctry = new SelectList(db.Countries.ToList(), "Id", "CountryName", ctryold);
- return View(D);
- }
- public JsonResult getcitybyid(int id)
- {
- db.Configuration.ProxyCreationEnabled = false;
- return Json(db.Cities.Where(a => a.CountryId == id), JsonRequestBehavior.AllowGet);
- }
- }
- }

Bikesh SrivastavaRank #108 · 20.3K reputationPosted Aug 31, 2016, 7:09 PM EDT
- var x = $('#Ctry').val();
insteadof- var x = $(this).val();
try this.Midhun TpRank #388 · 6.5K reputationPosted Aug 31, 2016, 8:47 PM EDT
ahmed salahRank #2,612 · 534 reputationPosted Aug 31, 2016, 10:46 PM EDT
Vinay SinghRank #604 · 4K reputationPosted Aug 31, 2016, 11:08 PM EDT
ahmed salahRank #2,612 · 534 reputationPosted Aug 31, 2016, 11:20 PM EDT
- var x = $('#Ctry').val();
insteadofahmed salahRank #2,612 · 534 reputationPosted Sep 1, 2016, 1:24 AM EDT
ahmed salahRank #2,612 · 534 reputationPosted Sep 1, 2016, 1:52 PM EDT
Midhun TpRank #388 · 6.5K reputationPosted Sep 1, 2016, 6:14 PM EDT
http://www.c-sharpcorner.com/forums/selected-district-not-retrieved-for-employee-in-edit-view-ge