I need to set the default value displayed by a @Html.DropDownListFor
Searching found: @ Html.DropDownListFor how to set default value
So, I did it in my code:
@Html.DropDownListFor(model => model.equipe, new SelectList(ViewBag.equiColaborador,"id","nome","Selecionar.."), htmlAttributes: new { @class = "form-control"})
But without success, the first record is always displayed.
My Controller
:
// GET: Colaboradores
public ActionResult Index()
{
if (Session["cod_cli"] != null)
{
string cod_cli = Session["cod_cli"].ToString();
ViewBag.equiColaborador = db.Equipes.ToList();
return View();
}
else
{
return RedirectToAction("Login", "Account");
}
}