
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);
- }
- }
- }
Midhun TpPosted Sep 1, 2016, 10:14 PM
http://www.c-sharpcorner.com/forums/selected-district-not-retrieved-for-employee-in-edit-view-ge
ahmed salahPosted Sep 1, 2016, 5:52 PM
ahmed salahPosted Sep 1, 2016, 5:24 AM
ahmed salahPosted Sep 1, 2016, 3:20 AM
- var x = $('#Ctry').val();
insteadofVinay SinghPosted Sep 1, 2016, 3:08 AM
ahmed salahPosted Sep 1, 2016, 2:46 AM
Midhun TpPosted Sep 1, 2016, 12:47 AM
Bikesh SrivastavaPosted Aug 31, 2016, 11:09 PM
- var x = $('#Ctry').val();
insteadof- var x = $(this).val();
try this.