Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:02:10+00:00 2026-06-18T00:02:10+00:00

I have a view model property to hold a list of dropdown selection values

  • 0

I have a view model property to hold a list of dropdown selection values like:

  private ListDictionary _claimDropdownValueCollection = new ListDictionary();
  public ListDictionary ClaimDropdownValueCollection { get { return _claimDropdownValueCollection; } set { _claimDropdownValueCollection = value; } }

On doing the GET, I am looping over a different ListDictionary also in my view model which contains “dropdown type” names:

@foreach (System.Collections.DictionaryEntry de in Model.CCSetting_ClaimDropdownTypeCollection) {
                        <div class="formRow">
                            <label>@EverythingToDoWith_CCSetting_ClaimDropdownTypes.getDropdownTypeName(Model.ccClaim.clientID, Convert.ToInt32(de.Key))</label>
                            <div class="formRight searchDrop">
                                @Html.DropDownListFor(m => m.ClaimDropdownValueCollection[@de.Key], (IEnumerable<SelectListItem>) @de.Value, new { @class = "chzn-select", @data_placeholder="Choose an option...", @style="width: 350px;" })
                            </div>
                            <div class="clear"></div>
                        </div>
                    }

So basically, this loads a bunch of dropdowns, their ‘label’ is printed as per the key in the dictionary. The ‘values’ for EACH dropdown are obtained from the VALUE of each dictionary, which contains an IENUMERABLE each.

All good so far. Now the user makes his selection on each dropdown and I do an HTTP POST. In the browser developer tools, I see the following data being posted back:

ClaimDropdownValueCollection[1]:2
ClaimDropdownValueCollection[2]:5
ClaimDropdownValueCollection[3]:
ClaimDropdownValueCollection[4]:11

So that is 4 dropdowns with keys 1,2,3,4 (my keys will be more complicated, simple keys here for my example’s sake) and three of the four have selections so I pass back the selected ID’s 2, 5 and 11.

But the problem is, I am unable to see this data as part of the view model listdictionary object when I debug inside the [HttpPost] controller method that receives the posted data. That is showing the “ClaimDropdownValueCollection” property to be empty.

I am expecting to be able to say something like:

foreach (DictionaryEntry de in vm.ClaimDropdownValueCollection) {
//do something here with de.Key and de.Value                        
                    }

So what am I doing wrong in the RAZOR code?… Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:02:12+00:00Added an answer on June 18, 2026 at 12:02 am

    The issue was with the HTML helpers and how I was posting back. Here’s how I resolved it (thanks to my CTO at work!):

    Created my view model property that will serve as the resource to populate from as:

    Dictionary<int, List<SelectListItem>> CCSetting_ClaimDropdownTypeCollection
    

    Created another dictionary with the SAME KEYS, whose VALUE will be the users selection:

    Dictionary<int, int> ClaimDropdownValueCollection
    

    Now on the RAZOR side, I am doing something like this (note the use of HTML.Hidden, and HTML.Dropdown instead of HTML.DropdownFor):

    @foreach (var de in Model.CCSetting_ClaimDropdownTypeCollection) {
                            <div class="formRow">
                                                                <div class="formRight searchDrop">
    @Html.Hidden("ClaimDropdownValueCollection[" + @de.Key + "]", @de.Key)
                                    @Html.DropDownList("ClaimDropdownValueCollection[" +  @de.Value + "]", @de.Value, new { @class = "chzn-select", @data_placeholder="Choose an option...", @style="width: 350px;" })
                                </div>
                                <div class="clear"></div>
                            </div>
                        }
    

    Sorry about not wording my question in a better way perhaps, I perhaps posted after hours of frustration and ended up doing a bad job at phrasing it. Getting the ‘Tumbleweed’ badge for this question motivated me to come back and post the solution. OK to close, hope someone someday runs into this!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view with 1 dropdown generated from Model property and 3 additional
I have a view model that has a property that looks like this Property
I have a view model with a property on it that looks like this:
Suppose I have a view model with a property that looks something like this:
I have a view model that looks like this: public class VenueIndexViewModel : BaseViewModel
I have a view model with a property Fields which is an ObservableCollection<FieldVM> .
How do I bind a view model property to the ListBox.SelectedItem property? I have
I have a view model with an Email address property and a Confirm Email
I have a property in my view model which returns a constant under some
In my ViewModel I have a property, which is a list of models: private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.