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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:55:23+00:00 2026-06-12T20:55:23+00:00

I want to add another dropdownlist. The below code works for one dropdown, but

  • 0

I want to add another dropdownlist. The below code works for one dropdown, but how would I add one for Categories?

public  ActionResult Create()
        {
            var ddl = new Users();
            ddl.DropDowns = userRepository.Getddl("Departments").Select(c => new SelectListItem
                                                                    {
                                                                        Value = c.DropdownID.ToString(),
                                                                        Text = c.DropdownText
                                                                    });


            ViewData["ListofProfiles"] = new SelectList(ListofProfiles, "Value", "Text");

            return View(ddl);
        }
  • 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-12T20:55:24+00:00Added an answer on June 12, 2026 at 8:55 pm

    Try to avoid the ViewData approach.Switch to Strongly typed way of doing this. Add another property to your View Model to carry one more dropdown items

    public class User
    {
      public int SelectedCountry { set;get;}
      public int SelectedProfile { set;get;}
      public List<SelectListItem> Countries  {set;get;}
      public List<SelectListItem> Profiles {set;get;}
    
      public User()
      {
         Countries =new List<SelectListItem>(); 
         Profiles =new List<SelectListItem>(); 
      }
    }
    

    Now set the collection in your GET action

    public ActionResult Create()
    {
      var vm=new User();
      vm.Countries=GetCountryItems();
      vm.Profiles=GetProfileItems();  
      return View(vm);
    }
    

    Where GetCountryItems and GetProfileItems are 2 methods which returns a list of SelectListItem objects for countries and Profiles from db.

    Do not make your controllers FAT. Just keep it simple and clean. Move away your code which fetch data from repository to a different layer. Easy to read and maintain 🙂

    And in your strongly typed view,

    @mode User
    @using(Html.BeginForm())
    {
      @Html.DropDownListFor(m => m.SelectedCountry,
                         new SelectList(Model.Countries, "Value", "Text"), "Select")
      @Html.DropDownListFor(m => m.SelectedProfile,
                         new SelectList(Model.Profiles, "Value", "Text"), "Select")
     <input type="submit" />
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code choice /m Do you want to add another
I have the following code (lifted from CSS-Tricks) and want to add another div
i have javascript as below html=<th>+<?php echo __(); ?>+</th>; I want to add another
at first,i delete one cell in tableView,then i want to add another new cell
i wrote the following javascript code,now i want to add another condition /change the
I have an XML below like this and I want to add in another
I want to add another dropdown list of countries in customer account register page.I
I have an array of objects and I want to add another object just
I have a column of Int Array. I want to add another column to
So I have a viewControllerA, and I want to add another View managed by

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.