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
zeeshan akram
1.4k
325
18k
MVC Cascading Drop Down Not Selected When Editing
May 17 2020 1:39 AM
When I edit record country list is loaded but the city list not loaded. For example, I have saved record Country USA and City are Newyork is not loaded if the USA country selected. This function works well when I add new Add Record But Edit I use in Edit Operation I have the Problem.
C#
List<Country> listCountry = _ICountry.listofCountry();
ViewBag.CountryList =
new
SelectList(listCountry,
"CountryID"
,
"CountryName"
);
public
JsonResult GetCity(
int
CountryID)
{
List<City> ctyList = _ILogin.GetCityList(CountryID);
return
Json(ctyList, JsonRequestBehavior.AllowGet);
}
<
div
class
=
"row"
>
<
div
class
=
"col-md-6"
>
<
label
class
=
"col-xs-3 control-label"
>
Country
</
label
>
<
div
class
=
"controls col-xs-9"
>
@Html.DropDownListFor(
m
=
>
m.CountryID, ViewBag.CountryList as SelectList, "Choose the Country Name", new { @
class
=
"input-border-btm"
})
</
div
>
</
div
>
<
div
class
=
"col-md-6"
>
<
label
class
=
"col-xs-3 control-label"
>
City
</
label
>
<
div
class
=
"controls col-xs-9"
>
@Html.DropDownListFor(
m
=
>
m.CityID, new SelectList(" "), "Choose City", new { @
class
=
"input-border-btm"
})
</
div
>
</
div
>
</
div
>
Jquery
<script>
$(document).ready(
function
() {
$(
"#CountryID"
).change(
function
() {
$.get(
"/Items/GetCity"
, { CountryID: $(
"#CountryID"
).val() },
function
(data) {
$(
"#CityID"
).empty();
$.each(data,
function
(index, row) {
$(
"#CityID"
).append(
"<option value='"
+ row.CityID +
"'>"
+ row.CityName +
"</option>"
)
});
});
})
});
</script>
Reply
Answers (
1
)
Improve page load speed
502 - Web server received in iis 10