1
Error:
Runtimebinderexception: Cannot implicitly Convert type 'Object' to 'System.Collections.Generic.Ienumerable<Microsoft.AspNetCore.Mvc.Rendering.Selectlistitem>'. An Explicit Conversion exists (are you Missing a cast?)
The Model:
public IEnumerable<SelectList> Emails { get; set; }
The Controller:
public IActionResult Create()
{
var mls =
(from geral in _context.Clientes
orderby geral.Email
select new { text = geral.Email, value = geral.Email }).ToList();
ViewBag.MailList = mls.AsEnumerable();
return View();
}
The View
:
<select asp-for="Emails" asp-items="@ViewBag.MailList"></select>
The error appears in the view, if I send a null object until the empty checkbox appears. I’ve tried every kind of conversion and nothing, someone has some light?
Select the view code
– novic
view:.. <select Asp-for="Emails" Asp-items="@Viewbag.Maillist"></select>
– Eudemar Tonatto
I fixed it. Edudemar, the type is not as it is being sent to View
– novic