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 8695053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:56:12+00:00 2026-06-13T00:56:12+00:00

I have 5 dropdowns, which are basically displaying Select, Yes and No. Initially they

  • 0

I have 5 dropdowns, which are basically displaying “Select”, “Yes” and “No”. Initially they are set to “Select”. Once he user chooses something, I am storing the data in a cookie (with Jquery) and eventually passing this to the ViewModel so that I can use it in the Controller.

When the user refreshes the page, I want these dropdown lists to be populated again with the value I have in the ViewModel.

At the moment I have the following code :-

Inside the View I have

<%: Html.DropDownList("FirstQuestYesNo", ViewData["FirstQuestYesNoData"] as SelectList, new { @class = "normalDropdowns" })%>

and in my controller I have the following :-

            var ddlYesNoData = new SelectList(new[]
                                      {
                                          new {ID="",Name=@Resources.GeneralTerms.GeneralTerms_Select},
                                          new {ID="Yes",Name=@Resources.GeneralTerms.GeneralTerms_Yes},
                                          new{ID="No",Name=@Resources.GeneralTerms.GeneralTerms_No},
                                      },
        "ID", "Name", 1);


        //Refresh the YesNo dropdown with the correct vals
        Dictionary<string, string> YesNoData = new Dictionary<string, string>();
        YesNoData.Add("FirstQuestYesNoData", viewModel.FirstQuestYesNoValue);
        YesNoData.Add("SecondQuestYesNoData", viewModel.SecondQuestYesNoValue);
        YesNoData.Add("ThirdQuestYesNoData", viewModel.ThirdQuestYesNoValue);
        YesNoData.Add("FourthQuestYesNoData", viewModel.FourthQuestYesNoValue);
        YesNoData.Add("FifthQuestYesNoData", viewModel.FifthQuestYesNoValue);

        foreach (var item in YesNoData)
        {
            ViewData[item.Key] = ddlYesNoData;
            if (item.Value != null)
            {
                var selected = ddlYesNoData.Where(x => x.Value == item.Value).First();
                selected.Selected = true;
            }
        }

So basically what I am doing is get the value of each dropdown from the viewModel, and then try to set that value inside my View. As a result of what I am doing, I am getting all the DropdownLists option as “Select” instead of the value inside my viewModel.

The problem is that I do not know how to “target” the specific DropDownList. How can I target the DropDown (in this case “FirstQuestYesNo”) from the Controller using my code?

Thanks for your help and time.

  • 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-13T00:56:15+00:00Added an answer on June 13, 2026 at 12:56 am

    In your controller action simply set the FirstQuestYesNo property to the corresponding value. For example:

    ViewData["FirstQuestYesNo"] = "Yes"; // this value might come from a cookie
    

    This will automatically preselect the option with value="Yes". Obviously this value will come from the cookie. You don’t need any foreach loops.

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

Sidebar

Related Questions

I have dropdown-Lists which have a lot of elements (>1000). When I select one
I have a dropdown list (FK) which I would like to set and display
I have a little dropdown menu similar <select> , which contolled from external js-function.
I have this HTML code which simulates a dropdown multi-checkbox <div> <div class=select> <span>Select
So I have this problem, which I don't see how it's happening. Basically I
I have a set of dynamically generated dropdown boxes on my page. basically I
Basically I have a form which right now has 2 drop downs with weights
I have two elements(dropdowns) which are very closely placed. These elements are required fields.
basically what i am trying to do i have 2 div which are hidden
I'd like to have a section with two dropdowns which effectively dictate which model

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.