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
Abhilash J A
501
2.4k
598.1k
How can I rebind the drowdownlist in Edit page MVC
Mar 7 2017 9:58 AM
Hello everyone,
I am working on MVC 5, there I have Viewmodel Class
'
PartnersVM '
.
public
class
PartnersVM
{
public
List<CountryVM> listCountry {
get
;
set
; }
public
PartnerVM listPartnerVM {
get
;
set
; }
}
public
class
CountryVM
{
public
int
idCountry {
get
;
set
; }
public
string
countries_name {
get
;
set
; }
}
public
class
PartnerVM
{
public
string
ServiceDistricts {
get
;
set
; }
public
string
ServiceStates {
get
;
set
; }
}
And this is ActionResult Get method.
[HttpGet]
public
ActionResult PremiumUserRegistration()
{
PartnersVM objcountrymodel =
new
PartnersVM();
objcountrymodel.listCountry =
new
List<CountryVM>();
objcountrymodel.listCountry = objPartnerBIL.ShowCountries().Select(item =>
new
CountryVM
{
idCountry = item.idCountry,
countries_name = item.countries_name
}).ToList();
return
View(
"PremiumUserRegistration"
, objcountrymodel);
}
After calling this actionresult now binding list of countries. And the dropdown onchage calling a jscript function for bind below dropdowns also.
View:
@Html.DropDownListFor(
model
=
>
model.listCountry, new SelectList(Model.listCountry, "idCountry", "countries_name"), "Select", new { @
class
=
"form-control "
, @
id
=
"ddlcountries"
, @
onchange
=
"return getuserstate.search(this.value)"
})
@Html.DropDownListFor(
model
=
>
model.listPartnerVM.ServiceStates, Enumerable.Empty
<
SelectListItem
>
(), "Select Country", new { @
id
=
"ddlstate"
, @
class
=
"form-control "
, @
onchange
=
"return getdistricts.search(this.value)"
})
@Html.DropDownListFor(
model
=
>
model.listPartnerVM.ServiceDistricts, Enumerable.Empty
<
SelectListItem
>
(), "Select State", new { @
id
=
"ddlDistrict"
, @
class
=
"form-control "
})
Now, all are working fine. But the problem is, I can not rebind those drowdown list while moving on edit page. Here Add/Edit page is one. How can I rebind the dropdownlist?
Please help me...
Reply
Answers (
5
)
MVC: call ajax script after check ModelState in controller?
How to Create View Like Show in Image Using MVC ?