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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:25:55+00:00 2026-06-08T01:25:55+00:00

I have a table in my DB like: I want to fill the select

  • 0

I have a table in my DB like:

enter image description here

I want to fill the select tag with the MainTab items using the Html.DropDownListFor() extension.

The hardest part is, I want these items to be a string like TabA_Name/TabB_Name/TabC_Name How can I do this ?

  • 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-08T01:25:57+00:00Added an answer on June 8, 2026 at 1:25 am

    Use View Model for the page that you have dropdownlist. For instance,

    public class MyViewModel
    {
        /* You will keep all your dropdownlist items here */
        public IEnumerable<SelectListItem> Items { get; set; }
    
        /* The selected value of dropdown will be here, when it is posted back */
        public String DropDownListResult         { get; set; }
    
    }
    

    In your controller where you return view model to view, fill the list and return that model.

    public ActionResult Create()
    {
        /* Create viewmodel and fill the list */
        var model = new MyViewModel();
    
        // TODO : Select all data from MainTab to variable. Sth like below.
        var data= unitOfWork.Reposityory.GetAll();
    
        /* Foreach of the MainTab entity create a SelectListItem */
        var dropDownListData =  data.Select().(x = > new SelectListItem 
        {
            /* Value of SelectListItem is the pk of MainTab entity. */
            Value = x.MainTabID,
    
            /* This is the string you want to display in dropdown */
            Text = x.TabA.Name + "/" + x.TabB.Name + "/" + x.TabC.Name
        });
    
        model.Items = new SelectList(dropdownListData, "Value", "Text");
    
        return View(model);
    }
    

    This is your view.

    /* Make your view strongly typed via your view model */
    @model MyNamespace.MyViewModel
    
    /* Define your dropdown such that the selected value is binded back to 
     * DropDownListResult propery in your view model */
    @Html.DropDownListFor(m => m.DropDownListResult, Model.Items)
    

    When you post your view back to controller, your view model should have DropDownListResult that is filled with the selected dropdownlist item.

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

Sidebar

Related Questions

I want to (loosely) have a stored procedure like select * from table where
I have a table like: id number year I want to find holes, or
I have an SQL table like this : sales(product,timestamp) I want to display a
I have query to show the table like this: but I want to PIVOT
I have two table like this job(id,title,location,...) job_page(id,id_job,id_page,page_name) For example I want to write
I have one table and I want to select 10 rows randomly. But I
So, here's the deal. I have an html table that I want to populate.
I would like to use form_for except I have class table inheritance models using
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have a table like this ID Name IsDeleted 1 Yogesh Null 2 Goldy

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.