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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:24:44+00:00 2026-05-20T17:24:44+00:00

On my application, I need to display some dropdownlist, linked to a display line.

  • 0

On my application, I need to display some dropdownlist, linked to a display line.

<table>
        <% foreach (var item in Model) { %>
                <td>
                <%= Html.Encode(item.COMPETENCE_LIBELLE) %>
            </td>
            <td>
                <%= Html.DropDownListFor(item.FK_NIVEAU_ID, (SelectList)ViewData["FK_Niveau"]%>
            </td>
<% } %>
</table>

However, I dont know why, the selected value of my ddlist is never displayed…

I havent got any problem to display the selected value of a single ddlist, but when its on a loop… I dont know what to do…

Any idea ?

  • 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-05-20T17:24:45+00:00Added an answer on May 20, 2026 at 5:24 pm

    If you need to display multiple dropdown lists then you might need to adapt your view model. So let’s take an example:

    public class ItemsViewModel
    {
        public string Label { get; set; }
        public string SelectedId { get; set; }
        public IEnumerable<SelectListItem> Values { get; set; }
    }
    
    public class MyViewModel
    {
        public IEnumerable<ItemsViewModel> Items { get; set; }
    }
    

    then have a controller action which will populate this view model:

    public ActionResult Index() 
    {
        var model = new MyViewModel
        {
            Items = new[]
            {
                // TODO: fetch from your repository
                new ItemsViewModel 
                { 
                    Label = "label 1",
                    Values = new[] 
                    { 
                        new SelectListItem { Value = "1", Text = "item 1" },
                        new SelectListItem { Value = "2", Text = "item 2" }
                    }
                },
                new ItemsViewModel 
                { 
                    Label = "label 2",
                    // Automatically preselect the second item in the ddl
                    SelectedId = "B",
                    Values = new[] 
                    { 
                        new SelectListItem { Value = "A", Text = "foo1" },
                        new SelectListItem { Value = "B", Text = "bar" }
                    }
                },
            }
        }
        return View(model);
    }
    

    and then have a corresponding strongly typed view:

    <table>
        <thead> 
            <tr>
                <th>Label</th>
                <th>Values</th>
            </tr>
        </thead>
        <tbody>
            <%= Html.EditorFor(x => x.Items)
        </tbody>
    </table>
    

    and in the corresponding editor template (~/Views/Shared/EditorTemplates/ItemsViewModel.ascx):

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.ItemsViewModel>" 
    %>
    <tr>
        <td>
            <%: Model.Label %>
        </td>
        <td>
            <%= Html.DropDownListFor(
                x => x.SelectedId, 
                new SelectList(Model.Items, "Values", "Text")
            ) %>
        </td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display some portion of html in my windows forms application. It's
Hi I'm developing a WPF application. I need to display some HTML content from
I am running a Tomcat application, and I need to display some time values.
I need to use an Accordion to display some totals on a LOB application
For some reason I need to display tabular data in my web application but
I'm developing a Web application. I need to display some decimal data correctly so
I'm working on a Grails application and I need to display some reports and
In my application I want to display some pictures (I need to have them
I need to modify an existing Java application to display some (static) text in
I need to display some data(some text message) from a URL* (an HTML file)

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.