TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rohit Singh
NA
749
88.8k
Getting error while loading values from database and display
Aug 19 2017 1:33 PM
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'.
Reply
Answers (
1
)
Vb.net Report Compiling using stimulsoft and crystalreport
Kindly assist to correct below codes