Get selected value of dropdownlist in asp.net MVC

Posted by Xulfee on Stack Overflow See other posts from Stack Overflow or by Xulfee
Published on 2010-05-08T09:48:53Z Indexed on 2010/05/08 9:58 UTC
Read the original article Hit count: 262

Filed under:
|
|

how can i get select value of dropdownlist and here is my code which is working fine.

    var list = new[] {   
    new Person { Id = 1, Name = "Name1" }, 
    new Person { Id = 2, Name = "Name2" }, 
    new Person { Id = 3, Name = "Name3" } 
};

var selectList = new SelectList(list, "Id", "Name", 2);
ViewData["People"] = selectList;

<%= Html.DropDownListFor(model => model.Peoples, ViewData["People"] as IEnumerable<SelectListItem>)%>

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about mvc