How do I create "options" in Select from a worksheet? [closed]

0

I would like to know if it is possible to dynamically generate options in C # selection?

For example, I have my selection:

 <select id="Selecao_itens" multiple="multiple" runat= server  size="3" class="selection">
   <option value="Celula1 da planilha">Desejo criar esses options</option>    
</select>  

Thank you !!

    
asked by anonymous 03.10.2018 / 15:00

1 answer

1

In the view I use this way:

@Html.DropDownListFor(model => model.ID_Funcionalidade, controller.ListarFuncionalidade() as SelectList, "Selecione...", new { @class = "form-control" })

I create a method in the controller to list the data that comes from somewhere I bring to the screen with type SelectList .

Example:

public SelectList ListarFuncionalidade(object id = null)
{
    var funcionalidade = _IFuncionalidadeApplicationService.GetAllAsNoTracking().ToList();

    IList<FuncionalidadeViewModel> funcionalidadeViewModel = Mapper.Map<IEnumerable<Funcionalidade>, IList<FuncionalidadeViewModel>>(funcionalidade);

    return new SelectList(funcionalidadeViewModel, "ID", "Nome", id);
}
    
03.10.2018 / 16:10