I have 4 table relation in sql server database is good
Country table
Id primarykey increment identity
Countryname
City table
Id primary key increment identity
Cityname
CountryId forignkey
Ditrict table
Id primarykey increment identity
Districtname
CityId forignkey
Employee table
Id primary key increment identity
fname
sname
salary
Bonus
districtid forignkey
Relation not have any proplem
when select items from country it fill city drop down list without any problem
but when i select item from city it not fill items in district why
something wrong in my code i do as following
my controller employee as following
EmployeeControllerpublic class EmployeeController : Controller
{
// GET: Employee
mytaskdbEntities db = new mytaskdbEntities();
public ActionResult Index()
{
return View(db.Employees.ToList());
}
public ActionResult Create()
{
ViewBag.CountryList = new SelectList(db.Countries.ToList(), "Id","Countryname");
return View();
}
public JsonResult getcitybyid(int id)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Cities.Where(a =>a.CountryId == id), JsonRequestBehavior.AllowGet);
}
public JsonResult getdistrictbyid(int id)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Districts.Where(a => a.CityId == id), JsonRequestBehavior.AllowGet);
}
}
}- @model LinqProject.Models.Employee
- @{
- Layout = null;
- }
- "viewport" content="width=device-width" />
Create - @using (Html.BeginForm())
- {
- FirstName:@Html.TextBoxFor(a=>a.fname)
- LastName:@Html.TextBoxFor(a => a.sname)
- Salary:@Html.TextBoxFor(a => a.Salary)
- Bonus:@Html.TextBoxFor(a => a.Bonus)
- Bonus:@Html.TextBoxFor(a => a.Active)
- CountryName:@Html.DropDownList("CountryList")
- CityName: name="CityId">
- District: name="districtId">
- "submit" />
- }

Bikesh SrivastavaRank #108 · 20.3K reputationPosted Aug 18, 2016, 2:21 AM EDT
ahmed salahRank #2,612 · 534 reputationPosted Aug 18, 2016, 2:27 AM EDT
Vinay SinghRank #604 · 4K reputationPosted Aug 18, 2016, 2:34 AM EDT