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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:14:20+00:00 2026-06-03T11:14:20+00:00

In my MVC application, I need to add a dropdown that would show a

  • 0

In my MVC application, I need to add a dropdown that would show a list of domain names.

I already have a ViewModel that contains multiple properties. I am not sure what the sequence of the steps should be:

  1. Add a new property to my ViewModel? What should be the type? List?
  2. Define a method that populates the above property with values.
  3. Use that property in the View? Use HTML.DropdownFor?

I know I should put some code in my Question, but right now I am having difficulty getting started with this…

EDIT:
Added the following property to the ViewModel:

 public IEnumerable<SelectListItem> DomainList { get; set; }

and implemented a method to return a list of Domains:

internal static List<Domain> FetchAllDomains()

Next in my controller action, I have:

var domains = FetchAllDomains().Select(d => d.DomainName);
return new EmailModel() {DomainList = domains };

But I get the following error:

Cannot implicitly convert type
‘System.Collections.Generic.IEnumerable’ to
‘System.Collections.Generic.IEnumerable’.
An explicit conversion exists (are you missing a cast?)

  • 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-03T11:14:29+00:00Added an answer on June 3, 2026 at 11:14 am

    1) Add a new property to my ViewModel? What should be the type? List?

    You need 2 properties to be more precise: an IEnumerable<SelectListItem> to hold all the available options and a scalar property to hold the selected value

    2) Define a method that populates the above property with values.

    Yes.

    3) Use that property in the View? Use HTML.DropdownFor?

    No, not in the view. The view doesn’t call any methods. A view works with the view model. It is the responsibility of the controller to pass a properly filled view model to the view.

    So for example:

    public class MyViewModel
    {
        public string SelectedValue { get; set; }
        public IEnumerable<SelectListItem> Values { get; set; }
    
        ... some other properties that your view might need
    }
    

    and then a controller action that will populate this view model:

    public ActionResult Index()
    {
        var model = new MyViewModel();
        model.Values = new[]
        {
            new SelectListItem { Value = "1", Text = "item 1" },
            new SelectListItem { Value = "2", Text = "item 2" },
            new SelectListItem { Value = "3", Text = "item 3" },
        };
        return View(model);
    }
    

    and finally the strongly typed view in which you will display the dropdown list:

    @model MyViewModel
    @Html.DropDownListFor(x => x.SelectedValue, Model.Values)
    

    UPDATE:

    According to your updated question you are have an IEnumerable<SelectListItem> property on your view model to which you are trying to assign a value of type IEnumerable<string> which obviously is impossible. You could convert this to an IEnumerable<SelectListItem> like this:

    var domains = FetchAllDomains().Select(d => new SelectListItem
    {
        Value = d.DomainName,
        Text = d.DomainName
    });
    return new EmailModel { DomainList = domains };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an ASP.NET MVC application that exists. I want to add a
I have an asp.net mvc application and now I need to add a web
I have asp.net mvc 3 application and I need to add some html to
I have been developing an asp.net mvc application where i need to make large
I am using sping3 mvc in my application. I have some entities which need
I am developing an application in asp.net mvc where i need to have Chat
I have an MVC application view that is generating quite a large HTML table
I have an ASP.NET MVC 3 application. I need to implement a file uploader
.Net MVC application also running Linq-to-SQL. I have seen many articles on grids that
We have an MVC.NET application that encounters fatal errors when it restarts. In our

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.