Good morning,
I am working on ASP.NET MVC and I have the task of creating a dropdownlist that shows two columns with data from the same table. For example:
I have looked for possible solutions and achieved the following implementation. It consists of composing a dictionary in which value a string with format (to encolumnar) containing the data to be displayed per row is stored.
//Controlador...
public ActionResult Create()
{
var dic_Aut = db.tblAuthorities.ToDictionary(s => s.AutId, s =>(s.AutNombre.PadRight(70) +
s.AutAbrev).ToString().Replace(" ","\xA0"));
ViewBag.AutId = new SelectList(dic_Aut, "Key", "Value");
//...
return View();
}
Then in the view, to achieve the effect of columns, the source must be monospace so that each character occupies the same space.
@*Vista...*@
<div class="form-group">
@Html.LabelFor(model => model.AutId, "Autoridad", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10 monospace">
@Html.DropDownList("AutId", null, htmlAttributes: new { @id = "AutId", @class = "form-control", required = "required", placeholder = "Este dato es necesario..." })
@Html.ValidationMessageFor(model => model.AutId, "", new { @class = "text-danger" })
</div>
</div>
The result is something like the following:
This solution is partial because:
- The fountain is not aesthetically pleasing.
- If the content of the first column exceeds the padding set (70), the text moves the second column.
- It would be desirable to show a dividing line as in the first image.
I would be very grateful if anyone can guide me towards a better approach.
Thanks for your time. Greetings!