SagarJadav06
SagarJadav06

Reputation: 1

Access list of multiple dropdowns using dictionary keyvalue pair. Selected value lost for Postback item

I am trying to display multiple dropdowns on post back on razor page in my ASP.NET MVC application inside a for loop using Dictionary<CountryCode, <selectList item with Country Selected>>.

Unfortunately, the selected value is lost and the dropdown is displayed with default selection.

enter image description here

Upvotes: 0

Views: 35

Answers (1)

SagarJadav06
SagarJadav06

Reputation: 1

Soultion found: The MVC Postback method required cleaning of ModalState as well. The Dynamically removed dropdowns were cleaned from our viewModel alone, cleaning it from the ModalState as well, solved the issue. Because: Dropdownlistfor in the back end has a field called attempted value that was causing the dropdown selected value to get wiped out.

Thanks

Upvotes: 0

Related Questions