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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:47+00:00 2026-05-17T20:01:47+00:00

I am looking for the best method for creating a drop down list editor

  • 0

I am looking for the best method for creating a drop down list editor template with MVC. There seem to be various methods but I can’t find any method that is best, everyone seems to do it differently. I am using MVC3 with Razor as well, so a method that works with this is preferred.

  • 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-17T20:01:47+00:00Added an answer on May 17, 2026 at 8:01 pm

    There are many ways and saying which is the best would be subjective and might not work in your scenario which by the way you forgot to describe in your question. Here’s how I do it:

    Model:

    public class MyViewModel
    {
        public string SelectedItem { get; set; }
        public IEnumerable<Item> Items { get; set; }
    }
    
    public class Item
    {
        public string Value { get; set; }
        public string Text { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new MyViewModel
            {
                // TODO: Fetch this from a repository
                Items = new[] 
                {
                    new Item { Value = "1", Text = "item 1" },
                    new Item { Value = "2", Text = "item 2" },
                    new Item { Value = "3", Text = "item 3" },
                }
            };
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                // redisplay the view to fix validation errors
                return View(model);
            }
    
            // TODO: The model is valid here => 
            // perform some action using the model.SelectedItem 
            // and redirect to a success page informing the user
            // that everything went fine
            return RedirectToAction("Success");
        }
    }
    

    View (~/Views/Home/Index.cshtml):

    @model MyApp.Models.MyViewModel
    
    @{ Html.BeginForm(); }
        @Html.EditorForModel()
        <input type="submit" value="OK" />
    @{ Html.EndForm(); }
    

    Editor template (~/Views/Home/EditorTemplates/MyViewModel.cshtml):

    @model MyApp.Models.MyViewModel
    
    @Html.DropDownListFor(x => x.SelectedItem, 
        new SelectList(Model.Items, "Value", "Text"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the best method to parse various XML documents using a Java
I am looking for the best method to run a Java Application as a
I'm looking for the best JavaScript editor available as an Eclipse plugin. I've been
What's the best way to create printable letters from an MVC application? I'm looking
I'm looking for some advice/opinions on the best way to approach creating a sort-of-dynamic
Im using Qt framework , and i looking for the best method to show
I am looking for best practices for detecting and preventing DOS in the service
I'm looking for best practices for establishing connections between Oracle 8 and Visual Studio
I'm looking for best practices for performing strict (whitelist) validation/filtering of user-submitted HTML. Main
I'm looking for best practices for using the same data in different places without

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.