Hello everyone, I want to read all the values from my table and display it on my view using code first approach of entity framework but i got an error in every try.
I have tried almost everything but couldn't achieve what I want..please solve this problem.. Review my Code Below:::
What I have tried:
This is My ActionMethod: in which i'm reading all the values from databsae.
[HttpGet]
public ActionResult ViewAll()
{
MenuRolesSample dbContext = new MenuRolesSample();
return View(dbContext.Menus.ToList());
}
This is my Viewpage: where I just want to display all the Names from the database table.
@model IEnumerable
@{
ViewBag.Title = "ViewAll";
Layout = "~/Views/sahred/_layout.cshtml";
}
@foreach (var item in Model)
{
}
Name
|
@Html.DisplayFor(M=>item.Name)
|
Name
|
@Html.DisplayFor(M=>item.Name)
|
The Error which I've been facing is:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MenuRoles.Models.Menu]', but this dictionary requires a model item of type 'MenuRoles.Models.Menu'.