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

  • Home
  • SEARCH
  • 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 8583281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:29:47+00:00 2026-06-11T21:29:47+00:00

Is there an overload for Html.DropDownList that will show a value from the model

  • 0

Is there an overload for Html.DropDownList that will show a value from the model as the currently selected item? In my view I insert a model using as using statement

 @using SchoolIn.Models

Then I access the model like this:

        if (Model.Enrollments != null)
        {   
            @Html.DropDownList("searchString", Model.Enrollments.FirstOrDefault().weekDays.Select(s => new SelectListItem { Text = s.ToString(), Value = s.ToString() }))   
        }

Here’s the code from my model:

 public virtual string classDays { get; set; }
 public string[] weekDays = new string[6]          { "Day", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
 public string[] WeekDays
 {
 get { return weekDays; }

When my view loads it presents a dropdown list that I can select from, I select a day and save the selection but when it loads again, I want the previously selected item to be the default selected in the list. How can I do this? I would really appreciate any help, thanks.

  • 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-06-11T21:29:49+00:00Added an answer on June 11, 2026 at 9:29 pm

    It looks like you should be able to set Selected on the appropriate item:

    @{
        var Items = Model.Enrollments.FirstOrDefault().weekDays.Select(s => 
            new SelectListItem { Text = s.ToString(), Value = s.ToString() 
                Selected = s.ToString().Equals(PreviouslySelectedValue)
            } 
        );
    }
    @Html.DropDownList("searchString", Items)   
    

    You could also use DropDownListFor, which should set the selected item to the value of the property.

    @Html.DropDownListFor(model => PreviouslySelectedValue, Items)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a Select overload that adds an index to each element of a
Why only one overload throws this exception? Little update: I understand that there was
There is a moment in my app, that I need to force to show
So it seems that the non-generic overload of Html.ActionLink() works nicely with HTML5 data-
Is there a use for the overload of AddModelError () that takes an Exception
In Html.Editor (technically EditorExtensions.Editor ) there is an overload with the signature of public
I'm working on a project that will auto-generate Word and HTML reports. If they
There are two ways to overload operators for a C++ class: Inside class class
Is there any way to overload the > (greater than) operator, to be able
Is there a way to overload base template class functions in derived classes, and

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.