Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MVC and Dropdownliast

MVC and Dropdownliast

Scheduled Pinned Locked Moved ASP.NET
questionhtmlasp-netarchitecture
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    future3839
    wrote on last edited by
    #1

    hi, do you know how can I add dropdown list?

                        <%Html.DropDownList(??????????)%>
    
    T 1 Reply Last reply
    0
    • F future3839

      hi, do you know how can I add dropdown list?

                          <%Html.DropDownList(??????????)%>
      
      T Offline
      T Offline
      TweakBird
      wrote on last edited by
      #2

      Using the DropDownList Helper The DropDownList helper renders a drop-down list. In its simplest form, DropDownList takes one parameter, the name of the ViewData key whose value is of type SelectList and that contains the option values for the drop-down list. The MVC framework uses the ModelState property of ViewData to determine the selected value. If the ModelState property is empty, the framework looks for an item whose Selected property is set. The following example shows markup for the DropDownList helper method.

      <%= Html.DropDownList("pets") %>

      The following code is a part of an Index action method in which values are added to a List object. The List object is passed to an instance of SelectList, which is then added to the ViewData object.

      List<string> petList = new List<string>();
      petList.Add("Dog");
      petList.Add("Cat");
      petList.Add("Hamster");
      petList.Add("Parrot");
      petList.Add("Gold fish");
      petList.Add("Mountain lion");
      petList.Add("Elephant");

      ViewData["Pets"] = new SelectList(petList);

      Note:**Both the DropDownList and ListBox helpers accept either a SelectList or MultiSelectList object. have a look on this link Click Here[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups