4
I have a list of vehicle models:
private List<ModeloRastreador> modelo = new List<ModeloRastreador>();
add the result that came from the bank
foreach (var m in modelo)
{
modeloRastreador.Add(new SelectListItem {
Text = m.Nome,
Value = Convert.ToString(m.ID)
});
}
step to my viewbag
ViewBag.ModelosVeiculos = modeloVeiculos;
and for the dropdown
@Html.DropDownList("ModeloID", new SelectList(ViewBag.ModelosVeiculos, "value", "text"),
new {
style = "width:280px",
@class = "form-control form-control-last",
@id = "ModeloID"
})
Up ai beauty, but I want to set a value, equal to HTML Selected.
Yes Tiago, that’s right, I decided to create a Viewbag.Selectedvalue and passing in the third parameter of the dropdown the value in the case of the ID that came from the database, which was to be selected, being thus @Html.Dropdownlist("Modeloid", new Selectlist(Viewbag.Modelslevehicles, "value", "text", Viewbag.Selectedvalue)
– Douglas