I don't understand how to pass this selectListitem in the controller, how to send that to the view ?
With return view("MyView", listItems ) ? But it says that listItems doesn't exist in the current context ! Have you an idea ? Thanks
@{
List<SelectListItem> listItems= new List<SelectListItem>();
listItems.Add(new SelectListItem
{
Text = "Exemplo1",
Value = "Exemplo1"
});
listItems.Add(new SelectListItem
{
Text = "Exemplo2",
Value = "Exemplo2",
Selected = true
});
listItems.Add(new SelectListItem
{
Text = "Exemplo3",
Value = "Exemplo3"
});
}
@Html.DropDownListFor(model => model.tipo, listItems, "-- Select Status --")
I precise that there is already a model in my view for a form. I want to fill one field of the form with the dropdownlist. That's why i whant to use the HtmlHelper DropDownListFor.