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

  • Home
  • SEARCH
  • 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 8334267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:17:24+00:00 2026-06-09T03:17:24+00:00

I am populating a dictionary object with key value pairs like this.. Dictionary<string, string>

  • 0

I am populating a dictionary object with key value pairs like this..

      Dictionary<string, string> twoValues = new Dictionary<string, string>();

        foreach (var item in query)
        {
            twoValues.Add(item.Name, item.Id);
        }

        return twoValues;

I am returning these value pairs to the controller and populating a MVC model (selectlists)

 model.Names = new SelectList(twoValues.Keys);
 model.Ids   = new SelectList(twoValues.Values);
 return model;

In the view I have an action link and a drop down. Drop down is populated with key values of the dictionary (in this case, key is text names, and value is ids)

//Action link 

<%=Html.ActionLink("link", "Method", "Controller", new { Id = ??  })%>

//Drop down   

<%=Html.DropDownList("names", Model.Names, "")%>      

How do I pass the Id associated with the selected Name in drop down to the controller via action link?

I tried having another drop down list next to names with the ids .. but somehow I need to maintain the link between the two drop downs.. since I am separating the dictionary key value pairs in the view for display…

I can have something like…

//Action link 

<%=Html.ActionLink("link", "Method", "Controller", new { Id = ??  })%>

//Drop down   

<%=Html.DropDownList("names", Model.Names, "")%>     
<%=Html.DropDownList("ids", Model.Ids, "")%>   

How do I pass the id via the action link for the selected ‘Name’ drop down list.

  • 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-09T03:17:26+00:00Added an answer on June 9, 2026 at 3:17 am

    I would recommend creating one dropdown that will have the value of the options equal to your id field and the text equal to your names. You should be able to create it using something this:

    Controller:

    IEnumerable<SelectListItem> items = yourQueryCode.Select(c => new SelectListItem
                   {
                     Value = c.ID.ToString(), 
                     Text = c.Name
                   });
    
    ViewBag.Names = items;
    

    HTML:

    <%= Html.DropDownList("Names", (IEnumerable<SelectListItem>) ViewBag.Names) %>
    

    This will allow you to get the ID linked to the name as the value of the dropdown when you do $('#dropdown').val().

    Preferably you would have the SelectList as part of your model that you return to the view, but the above will work as well. There will only have to be a few minor changes when you switch to returning via the model and the transition is pretty simple. Hopefully this is enough to get you headed in the right direction.

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

Sidebar

Related Questions

I am populating a list with about 25,000 items, using code like this: var
OK so I'm populating a selectbox with a JSON which looks something like this:
I am populating a Dictionary with the results of an sp call. The key
I have a Dictionary<int, string> cached (for 20 minutes) that has ~120 ID/Name pairs
I have a dictionary in python like this: x = {country:{city:population}:......} and I want
Right now I'm populating/setDefaults a zend_form like this from the controller: $data = array('user'
I'm declaring my dictionary like this: @property (weak, nonatomic) NSMutableDictionary *testVariableValues; @synthesize testVariableValues =
I'm populating my select box using the query shown below: <%=f.select :acoustic, options_for_select(User.includes(:roles).where( :roles
Must I do something like this? NSString *errorDescription = [error localizedDescription]; NSString *errorInfoStr =
This is as close as I've gotten to successfully populating an expandable listview from

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.