2
I created a DropDownList
by 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 customised attribute in options
of my select
, but I’m not sure how best to do that. My idea was to add a 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>
What if I made a method that was intelligent and carried the information of a standard class.?
– novic
They suggested to overwrite the
DropDownList
to predict this kind of situation, I think it’s more or less what you meant but with another method. If you want to post what you are imagining it is good to have several xD solutions– Caique Romero