I have a question about how to send my selectList
"status" to my View EditarUsuario
.
I've 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 the current status of the user to be set. 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 have seen, this Status
property is a normal field that brings 1 to Active and 0 to Inactive. In my View I put Helper
like this:
@Html.DropDownList("list", ViewData["list"] as SelectList)
And checking the generated HTML looks like this:
<select id="list" name="list">
<option value="2">Selecione</option>
<option value="1">Ativo</option>
<option value="0">Inativo</option>
</select>
How do I make the list look like this?
<select id="list" name="list">
<option value="2">Selecione</option>
<option value="1" selected>Ativo</option>
<option value="0">Inativo</option>
</select>