views:

38

answers:

1

Hello, I'm failing at getting the selected item on a mvc dropdown list. I can't stand viewdata, and every example uses it. Here is my code, thanks in advance.

//controller
  public ActionResult Register(Models.Person APerson)
        {

        }

  public class Person
    {
        public Person()
        {
            using (var model = new theModel())
            {

                var countriesList = (from c in model.Countries
                                     orderby c.Name ascending
                                     select c).ToList();
                Countries = new SelectList(countriesList, "ID", "Name");

            }

        }

        [Required]
        [DisplayName("Country")]
        public SelectList Countries { get; set; }


        public string SelectedCountry { get; set; }

    }

  <%=Html.DropDownListFor(m => m.SelectedCountry, Model.Countries) %>

I know there are bunch of Qs on this, but I can't find a simple example using the pattern.

A: 
Countries.SelectedValue
Scott
well that was simple, you are right, thanks. I thought it would be in the countries.selectedvalue... cheers.
if your coding in visual studio..."intellisense" is your friend.
Scott