TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed salah
NA
530
148k
Retrieve wrong city for district
Aug 31 2016 5:05 PM
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
;
}
<!DOCTYPE html>
<html>
<head>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>Edit</title>
<script src=
"~/scripts/jquery-1.10.2.js"
></script>
<script>
$(function () {
$(
"#ctry"
).change(function () {
$(
"#citylist"
).empty();
var x = $(
this
).val();
$.ajax({
url:
"/empcourse/getcitybyid"
,
data: { id: x },
success:function(res)
{
$.each(res, function (i, e) {
$(
"#citylist"
).append(
"<option value='"
+ e.Id +
"'>"
+ e.CityName +
"<option>"
)
});
}
});
});
$(
"#ctry"
).change();
});
</script>
</head>
<body>
<div>
@
using
(Html.BeginForm())
{
<div>
CountryName:@Html.DropDownList(
"ctry"
)
</div>
<div>
City:<select id=
"citylist"
name=
"CityId"
></select>
<br />
DistrictName:@Html.TextBoxFor(a => a.DistrictName)
</div>
<input type=
"submit"
/>
}
</div>
</body>
</html>
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);
}
}
}
Reply
Answers (
8
)
how to show dynamic Content in partial view MVC Razor view e
How to Update exist course id in EmployeeCourse table