I created a DropDownList
using the method below:
private void PopulateDropDown() {
//Chamo o método que obtém a lista de clientes da API
List<Models.Cliente> clientes = new Business.Cliente().Get();
//Rotorno a lista de clientes para a view
ViewData["Clientes"] = new SelectList(clientes, "Id", "Nome", "IdGrupoCliente");
}
Client Class:
public class Cliente{
public int Id { get; set; }
public string Nome { get; set; }
public int IdGrupoCliente { get; set; }
}
View:
<div class="input-group">
<span class="input-group-addon addon-no-border">
Selecione o cliente:
</span>
@Html.DropDownList("IdCliente", (SelectList)ViewData["Clientes"], new { @class = "form-control" })
</div>
I need to create a custom attribute in options
of my select
, however I'm not sure how to do this. My idea was to add data-IdGrupoCliente
as in the example below:
<select class="form-control" id="IdCliente" name="IdCliente">
<option value="1" data-IdGrupoCliente="10">Cliente Abc</option>
</select>