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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:50:12+00:00 2026-05-20T04:50:12+00:00

I am developing an ASP.Net MVC 3 Web application and believe my method of

  • 0

I am developing an ASP.Net MVC 3 Web application and believe my method of returning a list of items to a drop down list in the View is a bit long winded. Let me explain.

I have a ViewModel which contains an Equipment Entity and a SelectList to display a list of Categories.

public class AddEquipmentViewModel
{
    public Equipment equipment { get; set; }
    public SelectList categoryList { get; set; }

}

In the GET create method of my Equipment Controller, I return my ViewModel to the view, see below:

//Add new select list item named 'Please select option' to the top of list
        var categoryList = categoryService.GetAllCategories();
        var categorySelectListItems = categoryList.Select(c => new SelectListItem { Value = c.categoryID.ToString(), Text = c.categoryTitle  }).ToList();
        categorySelectListItems.Insert(0, new SelectListItem { Text = "Please select option", Value = string.Empty });

AddEquipmentViewModel viewModel = new AddEquipmentViewModel
        {
            equipment = new Equipment(),
            categoryList = new SelectList(categorySelectListItems.ToList(), "Value", "Text")
        };

I know I could discard the extra code before I create an instance of my ViewModel and just assign my Category List to the relevant ViewModel property like so

categoryList = new SelectList(categoryService.GetAllCategories(), "categoryID", "categoryTitle")

However, this then just returns a list of categories to my drop down list in my View, whereas, I would like to add a new SelectListItem, ie, “Please select option”.

I just feel that my approach to manually adding a new SelectListItem to my SelectList is a bit cumbersome and I would greatly appreciate if someone could share a better method?

Thanks for your time.

  • 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-20T04:50:12+00:00Added an answer on May 20, 2026 at 4:50 am
    <%= Html.DropDownList("name", new SelectList(...), "Your Combobox default message")%>
    

    Hope it helps

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

Sidebar

Related Questions

I am developing an asp.net mvc web application that makes much use of jquery
I'm developing a ASP.NET MVC 2 web application. So far, I managed to define
I am developing an asp.net mvc 2 web application. My clients will most likely
Good Morning All, I am developing a new ASP.net MVC web application. Part of
I have an Asp.Net MVC Web Application that I am developing. I have TeamCity
I'm developing an ASP.Net MVC site and on it I list some bookings from
I am developing an ASP.NET MVC application and I want to use OpenId. What
I am in the process of developing a large ASP.NET MVC application. I am
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I'm developing an ASP.NET MVC application where the content for any page can be

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.