Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
Getting error while loading values from database and display
Rohit Singh
7 years ago
285
Reply
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'.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Vb.net Report Compiling using stimulsoft and crystalreport
Kindly assist to correct below codes