I'm trying to do a dropdown in html

1

I'm trying to implement a DropDownList in a View of mine that is for form, but I need the value selected to go to ViewBag . This is my View where there is " Selected Car ", it would need to transform my from Textbox to DropDownList :

  

Thisisthecodeformyview:

<divclass="form-group">
     <label for="carro" class="col-sm-2 control-label">Carro selecionado</label>
         <div class="col-sm-10">
           <input type="number" class="form-control" id="carro" name="carro" required>
         </div>
</div>

This is my Controller :

public ActionResult FormData()
{
    ViewBag.Veiculo = veiculoDAO.Lista();
    return View();
}
    
asked by anonymous 02.01.2018 / 19:29

1 answer

1

Change your structures to these:

Html

<div class="form-group">
    <label for="carro" class="col-sm-2 control-label">Carro selecionado</label>
    <div class="col-sm-10">
        @Html.DropDownList("Veiculo")
    </div>
</div>

Code

public ActionResult FormData()
{
    var campoId = "nome do campo";
    var campoDescricao = "nome do campo Descricao"  
    ViewBag.Veiculo = new SelectList(veiculoDAO.Lista(), campoId , campoDescricao);
    return View();
}

References:

02.01.2018 / 19:33