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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:28:25+00:00 2026-05-27T22:28:25+00:00

I’m trying to create a view that will need 2 dropdown lists with MVC

  • 0

I’m trying to create a view that will need 2 dropdown lists with MVC 3. In my only other MVC app we used the Telerik controls that used the Ajax method to populate data. Now on this project we don’t use third party controls so I will be using the MVC SelectList for dropdowns. I’ve been reading a lot of articles on how to populate a SelectList but none of them say the same thing twice, always a different way to create the model, some use ViewData or ViewBag to hold the collections and pass to the view, etc.. no consistency.

What is the best accepted method to populate a dropdown in an MVC view that uses the model itself for the data, not ViewData. And when the user makes a selection from the list, submits and the HttpPost action is called, how do I access the selected value from the Model property of the select list property?

This is my current Model:

public class TemporaryRegistration {
    [Required]
    [Email(ErrorMessage = "Please enter a valid email address.")]
    [Display(Name = "Email address")]
    public string Email { get; set; }

    [Required]
    [Integer]
    [Min(1, ErrorMessage = "Please select an entity type.")]
    [Display(Name = "Entity Type")]
    public IEnumerable<SelectListItem> EntityType { get; set; }

    [Required]
    [Integer]
    [Min(1, ErrorMessage = "Please select an associated entity.")]
    [Display(Name = "Associated Entity")]
    public IEnumerable<SelectListItem> AssociatedEntity { get; set; }
}

This is my current view, it’s only using TextBoxFor where I need to use the dropdowns, how do I turn them into dropdowns?

@model Web.Models.TemporaryRegistration

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
    <legend>Create New ELM Select User</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EntityType)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EntityType)
            @Html.ValidationMessageFor(model => model.EntityType)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.AssociatedEntity)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.AssociatedEntity)
            @Html.ValidationMessageFor(model => model.AssociatedEntity)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

This is my current Post action:
How do I get the selected values out?

[HttpPost]
public ActionResult CreateUser(TemporaryRegistration registrationModel) {
    string newRegistrationGUID = string.Empty;
    if (!ModelState.IsValid) {
        return View();
    }

    TemporaryRegistrationEntity temporaryRegistration = null;
    temporaryRegistration = new TemporaryRegistrationEntity(registrationModel.Email, registrationModel.EntityType, registrationModel.AssociatedEntity);
    newRegistrationGUID = temporaryRegistration.Save();
    return Content("New registration was created with GUID " + newRegistrationGUID);
}
  • 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-27T22:28:26+00:00Added an answer on May 27, 2026 at 10:28 pm

    Continuing from comment…

    Let’s say you have a Model called Toy. Toy has properties like Name, Price, and Category:

    public class Toy()
    {
        public string Name;
        public double Price;
        public string Category
    }
    

    Now you want to build a form View to add a Toy, and people need to be able to select a category from a drop down of possibilities… but you don’t want to do this via ViewData or ViewBag for some reason.

    Instead of passing the Model to the View, create a ToyViewModel that has Name, Price, Category… but also has a collection of categories to populate the drop down:

    public class ToyViewModel()
    {
        public string Name;
        public double Price;
        public string Category
    
        public ICollection<string> Categories;
    }
    

    Now your controller does this:

    public ActionResult GetToyForm()
    {
        var viewModel = new ToyViewModel();
        viewModel.Categories = _service.GetListOfCategories();
        return View(viewModel);
    }
    

    Your View is bound to the ViewModel, and you use the model.Categories collection to populate your dropdown. It should look something like:

    @Html.DropDownListFor(model => model.Category, model.Categories)
    

    When you submit it, your controller does something like:

    [HttpPost]
    public ActionResult CreateToy(ToyViewModel _viewModel)
    {
        var model = new Toy();
        model.Name = _viewModel.Name
        // etc.
    
        _service.CreateToy(model);
    
        // return whatever you like.
        return View();
    }
    

    It is good practice to make ViewModels for binding to Views so you can tailor them to the needs of your presentation layer, while having your Models remain close to the data layer and business logic.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.