Selected District not retrieved for employee in edit view get

Posted by Ahmedsa under ASP.NET MVC on 8/27/2016 | Points: 10 | Views : 343 | Status : [Member] | Replies : 0
http://www.mediafire.com/view/s4p5n28xffd9zgg/add_district.jpg
see link to know what i need

in Edit view (get)

@model WebCourse.Models.Customemployee2

<script>
$(function () {
$("#CountryId").change(function () {
$("#citylist").empty();

var x = $(this).val();
$.ajax({
url: "/empcourse/getcitybyid",
data: { id: x },
success:function(res)
{
$.each(res, function (i, e) {
if (e.Id == $("#cityidhidden").val())
{
$("#citylist").append("<option selected value='" + e.Id + "'>" + e.CityName + "<option>")
}
else
{
$("#citylist").append("<option value='" + e.Id + "'>" + e.CityName + "<option>")
}


});
}
});


});
$("#CountryId").change();
$("#citylist").change(function () {
$("#districtlist").empty();
// alert("error");
var y = $(this).val();
$.ajax({
url: "/empcourse/getdistrictbyid",
data: { id: y },
success: function (res) {
$.each(res, function (i, e) {
if (e.Id == $("#disthidden").val()) {
$("#districtlist").append("<option selected value='" + e.Id + "'>" + e.DistrictName + "<option>")
}
else
{
$("#districtlist").append("<option value='" + e.Id + "'>" + e.DistrictName + "<option>")

}

});
}
});


});

$("#citylist").change();
});
</script>
</head>
<body>
<div>
@using (Html.BeginForm())
{
<div>
<input type="hidden" value="@ViewBag.Cityid" id="cityidhidden" />
<input type="hidden" value="@ViewBag.dist" id="disthidden" />
Country:@Html.DropDownList("CountryId")
<br />
City:<select id="citylist" name="CityId"></select>
<br />
District:<select id="districtlist" name="DistrictId"></select>


</div>
}

</div>
</body>
</html>
in Edit function in controller empcourse


mycourseEntities db = new mycourseEntities();



public ActionResult Edit(int id)
{
what i write in edit 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;





Responses

(No response found.)

Login to post response