INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

select item from city not fill items in district drop down linq

select item from city not fill items in district drop down linq

select item from city not fill items in district drop down linq

(OP)

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

Employee Controller
public 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);
}
}
}



my Employee view is

@model LinqProject.Models.Employee
@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Create</title>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(function () {
$("#CountryList").change(function () {
$("#citylist").empty();
// alert("error");
var x = $(this).val();
$.ajax({
url: "/Employee/getcitybyid",
data: { id: x },
success:function(res)
{
$.each(res, function (i, e) {
$("#citylist").append("<option value='"+e.id+"'>"+e.Cityname+"<option>")

});
}
});


});
$("#citylist").change(function () {
$("#districtlist").empty();
var y = $(this).val();
$.ajax({
url: "/Employee/getdistrictbyid",
data: { id: y },
success: function (res) {
$.each(res, function (i, e) {
$("#districtlist").append("<option value='" + e.id + "'>" + e.Districtname + "<option>")

});
}
});


});
});
</script>
</head>
<body>
<div>
@using (Html.BeginForm())
{
<div>
FirstName:@Html.TextBoxFor(a=>a.fname)

</div>
<div>
LastName:@Html.TextBoxFor(a => a.sname)

</div>
<div>
Salary:@Html.TextBoxFor(a => a.Salary)

</div>
<div>
Bonus:@Html.TextBoxFor(a => a.Bonus)

</div>
<div>
Bonus:@Html.TextBoxFor(a => a.Active)

</div>
<div>
CountryName:@Html.DropDownList("CountryList")

</div>
<div>
CityName:<select id="citylist" name="CityId"></select>
</div>
<div>
District:<select id="districtlist" name="districtId"></select>
</div>
<input type="submit" />
}
</div>
</body>
</html>

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close