Is it possible to display more than 1 field information in @Html.Dropdownlistfor?

Asked

Viewed 39 times

1

I would like to show more than 1 description

No controlle
//lista 
var tbuscar = new TituloPosAplicacao();
var listar = tbuscar.ListarTodos();
ViewBag.TituloPos = new SelectList(listar, "IDTITULOPOSS", "DESCRICAO", "MODALIDADE");
Na View
<div class="col-md-3 form-group">
    @Html.LabelFor(x => x.IDTITULOPOSS)
    @Html.DropDownListFor(x => x.IDTITULOPOSS, ViewBag.TituloPos as SelectList, new { @class = "form-control" })
    @Html.ValidationMessageFor(x => x.IDTITULOPOSS)
</div>

1 answer

1


Thus:

Controller

ViewBag.TituloPos = tbuscar.ListarTodos();

View

@Html.DropDownListFor(x => x.IDTITULOPOSS, 
    ((IEnumerable<TituloPosAplicacao>)ViewBag.TituloPos).Select(tpa =>
        new SelectListItem {
            Text = tpa.IDTITULOPOSS + " - " + tpa.DESCRICAO,
            Value = tpa.IDTITULOPOSS,
            Selected = (Model != null) && (Model.IDTITULOPOSS == tpa.IDTITULOPOSS)
        }), 
    "Escolha...", 
    htmlAttributes: new { @class = "form-control" }
)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.