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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:33:03+00:00 2026-05-16T22:33:03+00:00

I am using ASP.NET MVC 2 (.NET 3.5), and need to manually define what

  • 0

I am using ASP.NET MVC 2 (.NET 3.5), and need to manually define what shall be an Options list. When I do so I get a drop down menu, with each of the manual entries reading ‘System.Web.Mvc.SelectListItem’.

My view model defines the list as such:

    public SelectList YesNoList
    {
      get
      {
        List<SelectListItem> tmpList = new List<SelectListItem>();
        tmpList.Add(new SelectListItem {Text = "", Value = ""});
        tmpList.Add(new SelectListItem {Text = "Yes", Value = "1"});
        tmpList.Add(new SelectListItem {Text = "No", Value = "0"});
        YesNoList = new SelectList(tmpList,"");
      }
      private set{}
     }

In the view I reference this using the the Html.DropDownList:

Html.DropDownList("FieldName", viewmodel.YesNoList);

What I am expecting to be rendered on the final web page should be like:

<select id="FieldName" name="FieldName">
  <option value=""/>
  <option value="1">Yes</option>
  <option value="0">No</option>
</select>

Instead I get:

<select id="FieldName" name="FieldName">
  <option>System.Web.Mvc.SelectListItem</option>
  <option>System.Web.Mvc.SelectListItem</option>
  <option>System.Web.Mvc.SelectListItem</option>
</select>

I am at a loss, as I cannot figure out why the type is being returned so would appreciate it if anybody could point out to me what is wrong with the viewmodel definition, or point out a better way. I was hesitant to derive the SelectList from collections of C# classes as the SelectList would provide a consistant way to iterate through the values and display text.

Thanks in advance, hopefully somebody can help.

Cheers,

J

  • 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-16T22:33:04+00:00Added an answer on May 16, 2026 at 10:33 pm

    A dropdown can handle a List<SelectListItem> too, just send that in stead.

    Html.DropDownList("FieldName", viewmodel.YesNoList);
    

    and

    public List<SelectListItem> YesNoList
    {
      get
      {
        List<SelectListItem> YesNoList = new List<SelectListItem>();
        YesNoList.Add(new SelectListItem {Text = "", Value = ""});
        YesNoList.Add(new SelectListItem {Text = "Yes", Value = "1"});
        YesNoList.Add(new SelectListItem {Text = "No", Value = "0"});
        return YesNoList;
      }
      private set{}
     }
    

    you are actually doing it wrong on making the selectlist.

    it should be:

    new SelectList(tmpList, "Value", "Text"); 
    

    and then forget my above code. you can do this with any List, if you give it the list and the value and text “key”

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

Sidebar

Related Questions

Using ASP.NET MVC + jQuery : I need to use some values owned by
I'm using ASP.NET MVC to develop a website and I need to customize my
I need to create a web application using ASP.NET MVC, jQuery and web standards
I'm using asp.net mvc 3, My problem is I need to use the customized
i am using asp.net mvc 3. in one my of page. i need to
I'm developing a Web Site using ASP.NET MVC 3, Nowadays I need to encrypt
I need confirmation of my approach for this, I'm using EF and ASP.NET MVC
I am using FckEditor in Create.aspx page in asp.net mvc application. Since I need
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
I have a website using asp.net mvc in which I need to embed a

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.