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
Thabo Happy
NA
105
15.9k
The model item passed into the dictionary Is of type ...
Oct 8 2018 9:13 AM
Hello am getting this error when im trying to run my code to view data
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[NewKLUE.Models.Tutorial]', but this dictionary requires a model item of type 'NewKLUE.Models.IndexViewModel'.
My controller
public
async Task PHP()
{
var
tutorials = db.Tutorials.Where(t => t.CoursesName ==
"PHP"
);
return
View(await tutorials.ToListAsync());
}
My model
[Table(
"Tutorial"
)]
public
class
Tutorial
{
[Key]
public
int
TutorialId {
get
;
set
; }
[Required(ErrorMessage =
"Course Name is required"
)]
[Display(Name =
"Course Name"
)]
public
string
CoursesName {
get
;
set
; }
[Display(Name =
"Topic"
)]
public
string
Topic {
get
;
set
; }
[Required(ErrorMessage =
"Tutorial discription is required"
)]
public
string
Description {
get
;
set
; }
[AllowHtml]
public
string
Content {
get
;
set
; }
public
DateTime CreatedOn {
get
;
set
; }
[ForeignKey(
"User"
)]
public
string
UserId {
get
;
set
; }
public
virtual
ApplicationUser User {
get
;
set
; }
}
and my View
@model IEnumerable
@
using
NewKLUE.Models
@{
ViewBag.Title =
"PHP"
;
}
PHP
class
=
"table"
>
@Html.DisplayNameFor(model => model.User.FirstName)
@Html.DisplayNameFor(model => model.CoursesName)
@Html.DisplayNameFor(model => model.Topic)
@Html.DisplayNameFor(model => model.Description)
@Html.DisplayNameFor(model => model.Content)
@Html.DisplayNameFor(model => model.CreatedOn)
@
foreach
(var item
in
Model) {
@Html.DisplayFor(modelItem => item.User.FirstName)
@Html.DisplayFor(modelItem => item.CoursesName)
@Html.DisplayFor(modelItem => item.Topic)
@Html.DisplayFor(modelItem => item.Description)
@Html.DisplayFor(modelItem => item.Content)
@Html.DisplayFor(modelItem => item.CreatedOn)
@Html.ActionLink(
"Details"
,
"Details"
,
new
{ id=item.TutorialId })
}
Please help I dont understand the error at all
i ll apriciate any help.
Reply
Answers (
4
)
How to run background process in asp.net core 2.0
Remove a row from gridview but not from database in Asp.Net