Bring selected combo box filled manually

Posted on

Question :

I’m having trouble creating a combo of “Enabled” and “Disabled” by passing the value of the bank to bring it filled. In my controller , I created the following code:

InmyView,followingcode:

Theresultisthat,withthecoderunning,itwillalwaysappear”Enabled” in the combo.

    

Answer :

Since gestor.Status is a bool, or you change Value to bool:

lista.Add(new SelectListItem { Text = "Habilitado", Value = "True" });
lista.Add(new SelectListItem { Text = "Desabilitado", Value = "False" });

Or convert your gestor.Status to integer:

ViewBag.Status = new SelectList(lista, "Value", "Text", Convert.ToInt32(gestor.Status));

    

Leave a Reply

Your email address will not be published. Required fields are marked *