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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:14:04+00:00 2026-05-30T17:14:04+00:00

Currently I am using a Html.EditorFor control in a default ‘Create’ View page like

  • 0

Currently I am using a Html.EditorFor control in a default ‘Create’ View page like this.

 <%: Html.EditorFor(model => model.IsActive) %> 

I would like to convert this to a drop down with values and still be binded to the model in the view. My question is two fold.

  1. If there are only 2/3 values needed in the drop down..Is there a quick way to explicitly populate 2 or 3 values?

  2. If the list is big and needs to come from a sql query, how to do this?

Thanks in advance for the help.

  • 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-30T17:14:05+00:00Added an answer on May 30, 2026 at 5:14 pm

    In order to generate a dropdownlist you need 2 properties on your view model: a scalar property to bind the selected value to and a collection property which will contain the items to show in the dropdown.

    So you could define a view model:

    public class DropDownListViewModel
    {
        public string SelectedValue { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
    }
    

    and then on your main view model have a property of this type:

    public DropDownListViewModel Foo { get; set; }
    

    Now you could have a custom editor template for this type (~/Views/Shared/EditorTemplates/DropDownListViewModel.ascx):

    <%@ Control 
        Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DropDownListViewModel>" 
    %>
    <%= Html.DropDownListFor(x => x.SelectedValue, Model.Items) %>
    

    and then in your main view:

    <%= Html.EditorFor(x => x.Foo) %> 
    

    Now all that’s left is to have your controller action rendering the main view to fill the Foo property with the corresponding values. The could be hardcoded, come from a repository or whatever. It doesn’t really matter.

    On the other hand if you knew the values in advance you could hardcode them in the editor template (~/Views/Shared/EditorTemplates/YesNoDropDown.ascx):

    <%= Html.DropDownList(
        "", 
        new SelectList(
            new[] 
            { 
                new { Value = "true", Text = "Yes" },
                new { Value = "false", Text = "No" },
            }, 
            "Value", 
            "Text",
            Model
        )
    ) %>
    

    and then:

    <%= Html.EditorFor(x => x.IsActive, "YesNoDropDown") %> 
    

    or by decorating the IsActive property on your view model:

    [UIHint("YesNoDropDown")]
    public bool IsActive { get; set; }
    

    and then:

    <%= Html.EditorFor(x => x.IsActive) %> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using abcPDF 7 to convert HTML to PDF. This is done via
I'm currently downloading an HTML page, using the following code: Try Dim req As
I'm currently using XAMMP for mac (http://www.apachefriends.org/en/xampp-macosx.html) for development, however this package hasn't been
Currently I have a aspx page that is defined as: <%Using Html.BeginForm(SaveNotifications, Notifications, FormMethod.Post,
I am currently using the Html.EditorFor<> method for generating editor fields, however I would
I currently only have the create view for my Album class: @model MvcApplication1.Models.AlbumViewModel @{
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
Given the following view model and action using the DefaultModelBinder , it seems to
I have a PartialView strongly typed to a view model <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>
I'm currently using PHP and a regular expression to strip out all HTML comments

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.