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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:53+00:00 2026-05-25T12:42:53+00:00

This works for me but how do I do the same thing using html.dropdownlist

  • 0

This works for me but how do I do the same thing using html.dropdownlist?

Notice that the value passed is not the value that is shown to the user.

@model IEnumerable<MVR.Models.ViewIndividual>

<h2>Level1</h2>    
<select>
        @foreach (var item in Model) {
        <option value="@item.Case_Number">@item.Patient_Lastname , 
                                          @item.Patient_Firstname
        </option>
}
</select>
  • 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-25T12:42:53+00:00Added an answer on May 25, 2026 at 12:42 pm

    As always in an ASP.NET MVC application you start by defining a view model:

    public class MyViewModel
    {
        public string SelectedIndividual { get; set; }
        public SelectList Individuals { get; set; }
    }
    

    then you write a controller action that populates this view model from some data source or something:

    public ActionResult Index()
    {
        // TODO : fetch those from your repository
        var values = new[]
        {
            new { Value = "1", Text = "item 1" },
            new { Value = "2", Text = "item 2" },
            new { Value = "3", Text = "item 3" },
        };
    
        var model = new MyViewModel
        {
            Individuals = new SelectList(values, "Value", "Text")
        };
        return View(model);
    }
    

    and finally you have a strongly typed view using strongly typed helpers:

    @model MyViewModel
    @Html.DropDownListFor(
        x => x.SelectedIndividual,
        Model.Individuals
    )
    

    This being said, because I see that you are not using any view models in your application, you could always try the following ugliness (not recommended, do this at your own risk):

    @model IEnumerable<MVR.Models.ViewIndividual>
    
    <h2>Level1</h2>
    @Html.DropDownList(
        "SelectedIndividual",
        new SelectList(
            Model.Select(
                x => new { 
                    Value = x.Case_Number, 
                    Text = string.Format(
                        "{0}, {1}", 
                        x.Patient_Lastname, 
                        x.Patient_Firstname
                    ) 
                }
            ), 
            "Value", 
            "Text"
        )
    )
    

    Of course such pornography is not something that I would recommend to ever write in a view and I wouldn’t recommend even to my worst enemies.

    Conclusion: In an ASP.NET MVC application you should always be using view models and strongly typed views with strongly typed helpers (see first part of my answer).

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

Sidebar

Related Questions

This works: from x in table.AsEnumerable() where x.Field<string>(something) == value select x.Field<decimal>(decimalfield); but, this
Not sure if I've just missed something but this doesn't work: $(this).children('td.threadtitle a').html('thread title');
I am using Delphi TApplication.OnException Event to catch unhandled exceptions This works well but
$.post($(this).attr(action), $(this).serialize(), function(json) { alert('red'); AddItemAjax(json); }, json); This works in Chrome but not
I saw a similar post that was trying to do this same thing with
I'm trying something like this, but this example does not work. jsObj = {};
(Citing source at: http://jqueryui.com/demos/dialog/#modal-form ) As an example, this works great but each time
I use the line below in my C# winform app, this works great but
Server controls like Image.ImageUrl make this very easy, but trying to achieve the same
I'm using Opera 11.50 and I have a JavaScript-function that works as a callback

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.