Im trying to retrieve data from my localDb in a cshtml file like this:
@Html.LabelFor(model => model.TIPOCLIENTE, "TIPO CLIENTE", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@{List<SelectListItem> listItems = new List<SelectListItem>();
foreach (var item in Model.TipoClienteNamespace.TipoClienteValor)
{
listItems.Add(new SelectListItem
{
Text =(string) item.Descricao
});
}}
@Html.DropDownList("TIPO CLIENTE", listItems, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.TIPOCLIENTE)
</div>
But I get an error "Object reference not set to an instance of an object." on this line
foreach (var item in Model.TipoClienteNamespace.TipoClienteValor)
Anyone can help me?