It seems like this seemingly simple task has never been done before.
I have a controller with an action that retrieves my table cultures that contain my language info:
[HandleError]
[ChildActionOnly]
public ActionResult LanguageDropdownlist()
{
var languageDropdownlist = _unitOfWork.CulturesRepository.Get();
return PartialView("_LanguageSelectionPartial", languageDropdownlist.ToList());
}
languageDropdownlist is structured as follows:
List languageDropdownlistItems
[0]
- display_name
- id
- name
- ...
[1]
- display_name
- id
- name
- ...
[2]
- display_name
- id
- name
- ...
[3]
- display_name
- id
- name
- ...
I pass a list to the view.
In the view do the following:
@model List<ArtWebShop.Models.cultures>
<p>
@Html.DropDownList("name", (IEnumerable<SelectListItem>)Model)
</p>
How for the love of God do I populate the dropdownlist, the above code that is located in the view obviously doesn't work, but I can't seem to find a single explanation with code from the controller and the view.
P.S.: I do not wish to use viewData or viewBag.