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
Mark Tabor
589
2k
460.1k
The model item passed into the dictionary is of type 'System
Dec 11 2019 12:02 PM
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[CMS_Monitoring.Models.Semester]', but this dictionary requires a model item of type 'CMS_Monitoring.Models.Student'.
I am not sure what is wrong I have checked and it looks everything is correct check my model class my controller code my View and my table
My Table is
My Controller :
public
class
SemestersController : Controller
{
private
DatabaseContext db =
new
DatabaseContext();
// GET: Semesters
public
ActionResult Index()
{
var semesters = db.Semesters.Include(s => s.Programs).Include(s => s.years);
return
View(semesters.ToList());
}
// GET: Semesters/Details/5
public
ActionResult Details(
int
? id)
{
if
(id ==
null
)
{
return
new
HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Semester semester = db.Semesters.Find(id);
if
(semester ==
null
)
{
return
HttpNotFound();
}
return
View(semester);
}
}
}
---MY VIEW IS
@model IEnumerable<CMS_Monitoring.Models.Semester>
@{
ViewBag.Title =
"Index"
;
Layout =
"~/Views/Shared/_LayoutStudent.cshtml"
;
}
<h2>Index</h2>
<p>
@Html.ActionLink(
"Create New"
,
"Create"
)
</p>
<table
class
=
"table"
>
<tr>
<th>
@Html.DisplayNameFor(model => model.Programs.Program_Title)
</th>
<th>
@Html.DisplayNameFor(model => model.years.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Semester_Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Semester_Code)
</th>
<th>
@Html.DisplayNameFor(model => model.Semester_Duration_In_Weeks)
</th>
<th>
@Html.DisplayNameFor(model => model.Status)
</th>
<th>
@Html.DisplayNameFor(model => model.Semester_Start_Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Semester_End_Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Semester_Credit_Hours)
</th>
<th>
@Html.DisplayNameFor(model => model.Date_Created)
</th>
<th>
@Html.DisplayNameFor(model => model.Date_Modified)
</th>
<th>
@Html.DisplayNameFor(model => model.Added_By)
</th>
<th></th>
</tr>
@
foreach
(var item
in
Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Programs.Program_Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.years.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Semester_Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Semester_Code)
</td>
<td>
@Html.DisplayFor(modelItem => item.Semester_Duration_In_Weeks)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.DisplayFor(modelItem => item.Semester_Start_Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Semester_End_Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Semester_Credit_Hours)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Created)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Modified)
</td>
<td>
@Html.DisplayFor(modelItem => item.Added_By)
</td>
<td>
@Html.ActionLink(
"Edit"
,
"Edit"
,
new
{ id=item.Semester_Id }) |
@Html.ActionLink(
"Details"
,
"Details"
,
new
{ id=item.Semester_Id }) |
@Html.ActionLink(
"Delete"
,
"Delete"
,
new
{ id=item.Semester_Id })
</td>
</tr>
}
</table>
it gives this error on index i just check the index
Reply
Answers (
9
)
best design for an responsibility system
How to get Values Like 1.1023