MVC 3 - Populating DropdownList from web services

Binding DropDown Control to .Net MVC

Your Controller:

// getting data logic
//var data = ...

IEnumerable<SelectListItem> items = data.Select(c => new SelectListItem { Value = c.immotypid.ToString(), Text = c.immotyp }); ViewBag.DDImmoTyp = items; return PartialView("your view");

Your View:

@Html.Action("Index", "SearchImmoSurface");

Author

Caglar Tasci

Beauty is more important in computing than anywhere else in technology because software is so complicated. Beauty is the ultimate defence against complexity. — David Gelernter

comments powered by Disqus