SelectList

Last post 09-09-2008 2:25 PM by tgmdbm. 1 replies.

Sort Posts:

  • SelectList

    09-09-2008, 11:58 AM
    • Contributor
      3,569 point Contributor
    • shapper
    • Member since 11-28-2004, 9:15 PM
    • Posts 2,947

    Hello,

    On my view I have a DropDownList that should contain the usual targets of an HTML anchor: _blank, _self, ...

    I want the names to be different from the values so I am passing to my view in the ViewData a SelectList named Targets:

          SelectList targets;
          targets.Items.Add("Blank", "_blank");

    I am getting an error on adding the items. Add is not recongnized.

    Any idea what I am doing wrong here?

    Thanks,

    Miguel

     

  • Re: SelectList

    09-09-2008, 2:25 PM
    Answer
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 9:08 AM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    thats because there is no Add method on SelectList !!!

    use:

    var targets = new Dictionary<string, string>{ { "Blank", "_blank" }, ... }
    var targetSelectList = new SelectList( targets, "Key", "Value" );

Page 1 of 1 (2 items)