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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:39:50+00:00 2026-06-10T12:39:50+00:00

I have a drop down list in asp.net using nested for loops in a

  • 0

I have a drop down list in asp.net using nested for loops in a view, as well as variables I’ve
passed from a controller. The value that is displayed to the user is supposed to be the name of a stop, and the value is an id of that stop. Both the names and the stop ids are in lists I’ve passed from the controller to the view. But, when the drop down list is displayed, the first stop name is repeated for the entire list. I know that the right stop id is being selected, but the name is repeating. Here is my code:

 <select id="stop" onchange="sendInfo();">

@foreach(var blah in ViewBag.foobar)
{
  foreach (var foo in ViewBag.stops)
    { 
      <option value="@foo">@blah</option>
    }
}
 </select>

foo is the stop id that is correctly used, but blah is the name of the stop name, which is repeated. I feel like I’m so close but not quite there. I hope this was clear enough, it is confusing to explain.

  • 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-10T12:39:52+00:00Added an answer on June 10, 2026 at 12:39 pm

    I’m not positive I understand what you’re saying, but if there’s a 1:1 relationship between stops and IDs, why don’t you make a class containing both, like

    public class Stop
    {
        public string Name { get; set; }
        public int Id { get; set; }
    }
    

    and pass in a list of those and do a single loop:

    @{
        var stops = (IEnumerable<Stop>)ViewBag.Stops;
    }
    
    <select>
        foreach (var stop in stops)
        {
            <option value="@stop.Id">@stop.Name</option>
        }
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.NET 3.5 I have a drop-down list called lstCountry with an
I have a list of drop down lists populated form a database(using ASP.NET). These
I have an ASP.NET MVC application. I am having multiple drop-down list in my
I'm using classic asp, I have a drop down list that the user selects
I have an asp.net drop down list that has a number of items, users
I am using ASP.Net MVC. I have a partial view which has a form
I am trying to correct the sort order of my ASP.NET drop down list.
I have two tables: I want to fill an ASP.NET server control drop down
Requirment: I have a drop down list on my view page, displaying a list
I am using Asp.net dropdownlist in one of my form ..I have two dropdown

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.