jeudi 2 février 2017

ASP.NET MVC how to show DropDownList

I am trying to add Items into DropDownList without database. But output only shows "Testing..."

My Model class.

    public class DropDownListData
    {
        public DropDownListData()
        {
            City = new List<SelectListItem> { };
        }

        public List<SelectListItem> City;
    }

Controller

           public ActionResult Travel()
           {
               DropDownListData ddld = new DropDownListData();

               ddld.City = new List<SelectListItem>
               {
                   new SelectListItem {Value = "Paris" ,Text = "Paris"},
                   new SelectListItem {Value = "Moscow",Text = "Moscow"},
                   new SelectListItem {Value = "Yerevan" ,Text = "Yerevan" }
               };

               return View(ddld);
           }

View

@model ASP.NET.Test.Models.DropDownListData

@{
    Layout = null;
}

Testing...
@{
    Html.DropDownList("series", Model.City, "Choose City");
}

Why I don't see DropDownList. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire