Hello, I'm creating a project with VS2017 using .NET Core MVC web app template.
I added an EF controller with CRUD operations to manage users in a wine-related web app and generated the corresponding Views.
So my problem is:
An unhandled exception occurred while processing the request.
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List`1[HajaBinho.Models.Utilizador]', but this ViewDataDictionary instance requires a model item of type 'HajaBinho.Models.Utilizador'.
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(object value)
The app can´t list the users already in the Database. I send the info from the controller to the view like this:
public async Task<IActionResult> Index()
{
return View(await _context.Utilizador.ToListAsync());
}
and the View receives an IEnumerable:
@model IEnumerable<HajaBinho.Models.Utilizador>
@{
ViewData["Title"] = "Index";
}
<h2>Index</h2>
Am I not sending a List to the view dictionary?
Also, this code was generated by Visual studio I don´t know why it breaks. It was working before.
Please help, cheers.