7
I’m having a question about how to send my selectList
"status" to my View EditarUsuario
.
I created my list with the following items:
var list = new SelectList(new[]
{
new{ID="2",Name="Selecione"},
new{ID="1",Name="Ativo"},
new{ID="0",Name="Inativo"},
}, "ID", "Name");
ViewData["list"] = list;
I would like it to come set the current user status. I have in my model the status coming from the bank:
public int Id { get; set; }
public string CodigoUsuario { get; set; }
public string NomeUsuario { get; set; }
public int Status { get; set; }
As you’ve seen, this property Status
is a normal field that brings 1 to Active and 0 to Inactive. In my View put the Helper
in this way:
@Html.DropDownList("list", ViewData["list"] as SelectList)
And when checking the generated HTML this way:
<select id="list" name="list">
<option value="2">Selecione</option>
<option value="1">Ativo</option>
<option value="0">Inativo</option>
</select>
How do I set the list like this?
<select id="list" name="list">
<option value="2">Selecione</option>
<option value="1" selected>Ativo</option>
<option value="0">Inativo</option>
</select>
Perfect, it worked exactly as I would like. Thank you very much @Randrade...
– Luciano Carlos
thank you very much!
– Glauco Oliveira