Mark Tabor

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 :
  1. public class SemestersController : Controller  
  2. {  
  3. private DatabaseContext db = new DatabaseContext();  
  4. // GET: Semesters  
  5. public ActionResult Index()  
  6. {  
  7. var semesters = db.Semesters.Include(s => s.Programs).Include(s => s.years);  
  8. return View(semesters.ToList());  
  9. }  
  10. // GET: Semesters/Details/5  
  11. public ActionResult Details(int? id)  
  12. {  
  13. if (id == null)  
  14. {  
  15. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);  
  16. }  
  17. Semester semester = db.Semesters.Find(id);  
  18. if (semester == null)  
  19. {  
  20. return HttpNotFound();  
  21. }  
  22. return View(semester);  
  23. }  
  24. }  
  25. }
---MY VIEW IS
  1. @model IEnumerable<CMS_Monitoring.Models.Semester>  
  2. @{  
  3. ViewBag.Title = "Index";  
  4. Layout = "~/Views/Shared/_LayoutStudent.cshtml";  
  5. }  
  6. <h2>Index</h2>  
  7. <p>  
  8. @Html.ActionLink("Create New""Create")  
  9. </p>  
  10. <table class="table">  
  11. <tr>  
  12. <th>  
  13. @Html.DisplayNameFor(model => model.Programs.Program_Title)  
  14. </th>  
  15. <th>  
  16. @Html.DisplayNameFor(model => model.years.Name)  
  17. </th>  
  18. <th>  
  19. @Html.DisplayNameFor(model => model.Semester_Title)  
  20. </th>  
  21. <th>  
  22. @Html.DisplayNameFor(model => model.Semester_Code)  
  23. </th>  
  24. <th>  
  25. @Html.DisplayNameFor(model => model.Semester_Duration_In_Weeks)  
  26. </th>  
  27. <th>  
  28. @Html.DisplayNameFor(model => model.Status)  
  29. </th>  
  30. <th>  
  31. @Html.DisplayNameFor(model => model.Semester_Start_Date)  
  32. </th>  
  33. <th>  
  34. @Html.DisplayNameFor(model => model.Semester_End_Date)  
  35. </th>  
  36. <th>  
  37. @Html.DisplayNameFor(model => model.Semester_Credit_Hours)  
  38. </th>  
  39. <th>  
  40. @Html.DisplayNameFor(model => model.Date_Created)  
  41. </th>  
  42. <th>  
  43. @Html.DisplayNameFor(model => model.Date_Modified)  
  44. </th>  
  45. <th>  
  46. @Html.DisplayNameFor(model => model.Added_By)  
  47. </th>  
  48. <th></th>  
  49. </tr>  
  50. @foreach (var item in Model) {  
  51. <tr>  
  52. <td>  
  53. @Html.DisplayFor(modelItem => item.Programs.Program_Title)  
  54. </td>  
  55. <td>  
  56. @Html.DisplayFor(modelItem => item.years.Name)  
  57. </td>  
  58. <td>  
  59. @Html.DisplayFor(modelItem => item.Semester_Title)  
  60. </td>  
  61. <td>  
  62. @Html.DisplayFor(modelItem => item.Semester_Code)  
  63. </td>  
  64. <td>  
  65. @Html.DisplayFor(modelItem => item.Semester_Duration_In_Weeks)  
  66. </td>  
  67. <td>  
  68. @Html.DisplayFor(modelItem => item.Status)  
  69. </td>  
  70. <td>  
  71. @Html.DisplayFor(modelItem => item.Semester_Start_Date)  
  72. </td>  
  73. <td>  
  74. @Html.DisplayFor(modelItem => item.Semester_End_Date)  
  75. </td>  
  76. <td>  
  77. @Html.DisplayFor(modelItem => item.Semester_Credit_Hours)  
  78. </td>  
  79. <td>  
  80. @Html.DisplayFor(modelItem => item.Date_Created)  
  81. </td>  
  82. <td>  
  83. @Html.DisplayFor(modelItem => item.Date_Modified)  
  84. </td>  
  85. <td>  
  86. @Html.DisplayFor(modelItem => item.Added_By)  
  87. </td>  
  88. <td>  
  89. @Html.ActionLink("Edit""Edit"new { id=item.Semester_Id }) |  
  90. @Html.ActionLink("Details""Details"new { id=item.Semester_Id }) |  
  91. @Html.ActionLink("Delete""Delete"new { id=item.Semester_Id })  
  92. </td>  
  93. </tr>  
  94. }  
  95. </table>
it gives this error on index i just check the index

Answers (9)