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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:41:38+00:00 2026-06-15T23:41:38+00:00

Why is the initial value of my dropdownlist not showing? I’m using: @Html.DropDownList("DropDownValues", new

  • 0

Why is the initial value of my dropdownlist not showing? I’m using:

@Html.DropDownList("DropDownValues", new SelectList(ViewBag.sellectedSubjectsId, "Initial Value")); 

What am I doing wrong?

  • 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-15T23:41:39+00:00Added an answer on June 15, 2026 at 11:41 pm

    Try to avoid using Dynamic stuff like ViewBag and ViewData for transferring data between action method and views. Use strongly typed view models.

    Assume your view is to Create a new course where user has to select one subject from a list of subjects, create a view model like this

    public class CourseVM
    {
      public List<SelectListItem> Subjects { set;get;}
      public int SelectedSubject { set;get;}
      public CourseVM()
      {
        Subjects=new List<SelectListItem>();
      }
    }
    

    And in your GET action, create an object of your view model and fill the Subjects property.

    public ActionResult Create()
    {
      var vm=new CourseVM();
      //the below is for demo. replace with database data
      vm.Subjects.Add(new SelectListItem{ Value="1", Text="Maths"});
      vm.Subjects.Add(new SelectListItem{ Value="2", Text="English"});
      return View(vm);
    }
    

    Now in your view, which is strongly typed to your view model.

    @model CourseVM
    @using (Html.BeginForm())
    {
     //Other form elements as well
     @Html.DropdownListFor(x=>x.SelectedSubject,
                         new SelectList(Subjects,"Value","Text"),"Select one")
      <input type="submit" />
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C, how to configure the initial settings for some program, using key-value pairs,
For some reason the dropdownlist's initial value doesnt get set. It always loads some
I have the following HTML/JS that shows an initial value, removes it when you
How can I determine the initial value of a select item? This does not
I don't want to give an initial value. I want to set these later
I'm trying to set an initial value in my jquery ui datepicker. I've tried
I'm trying to set the initial value of a input field. In the template,
I have a form with an initial value, but I can't get the initial
I have a property in WCF service class with a initial value, as shown
I'm trying to find a way of displaying the text of the selected/initial value

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.