Class
public class ConfiguracaoEstado
{
....
[Required(ErrorMessage = "Selecione ao menos um estado.")]
[Display(Name = "Estado")]
public int EstadoID { get; set; }
...
}
Controller
private void createViewBag(ConfiguracaoEstado configuracaoestado)
{
ViewBag.EstadoID = new SelectList(db.Estado, "Id", "uf", configuracaoestado.EstadoID);
....
}
View
<div class="form-group">
@Html.LabelFor(model => model.EstadoID, "Estado", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("EstadoID", String.Empty);
@Html.ValidationMessageFor(model => model.EstadoID)
</div>
</div>
I would like that when running ActionResult Edit(int? id)
DropDownList
was disabled.
I tried this way:
@Html.DropDownList("EstadoID", String.Empty, new { disabled = Model != null});
and did not work.
So I tried this way:
@Html.DropDownListFor(model => model.EstadoID,
(SelectList)ViewBag.EstadoID,
String.Empty, new {disabled = Model != null}
)
Then the following happens:
DropDownList
. String.Empty
, it displays the contents, but not the contents, but the first one in the table. With bringing the correct contents of DropDownList
and disabling it?