4
Answers

The model item passed into the dictionary Is of type ...

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
  1. public async Task PHP()  
  2.        {  
  3.            var tutorials = db.Tutorials.Where(t => t.CoursesName == "PHP");  
  4.            return View(await tutorials.ToListAsync());  
  5.        }  
My model
  1. [Table("Tutorial")]  
  2.    public class Tutorial  
  3.    {  
  4.        [Key]  
  5.        public int TutorialId { getset; }  
  6.          
  7.        [Required(ErrorMessage = "Course Name is required")]  
  8.        [Display(Name = "Course Name")]  
  9.        public string CoursesName { getset; }  
  10.   
  11.         
  12.        [Display(Name = "Topic")]  
  13.        public string Topic { getset; }  
  14.   
  15.        [Required(ErrorMessage = "Tutorial discription is required")]  
  16.        public string Description { getset; }  
  17.   
  18.        [AllowHtml]  
  19.        public string Content { getset; }  
  20.   
  21.        public DateTime CreatedOn { getset; }  
  22.   
  23.        [ForeignKey("User")]  
  24.        public string UserId { getset; }  
  25.   
  26.        public virtual ApplicationUser User { getset; }  
  27.    }  
and my View
  1. @model IEnumerable  
  2. @using NewKLUE.Models  
  3. @{  
  4.     ViewBag.Title = "PHP";  
  5. }  
  6.   
  7. PHP

      
  8.   
  9.   
  10. class="table">  
  11.       
  12.           
  13.             @Html.DisplayNameFor(model => model.User.FirstName)  
  14.           
  15.           
  16.             @Html.DisplayNameFor(model => model.CoursesName)  
  17.           
  18.           
  19.             @Html.DisplayNameFor(model => model.Topic)  
  20.           
  21.           
  22.             @Html.DisplayNameFor(model => model.Description)  
  23.           
  24.           
  25.             @Html.DisplayNameFor(model => model.Content)  
  26.           
  27.           
  28.             @Html.DisplayNameFor(model => model.CreatedOn)  
  29.           
  30.           
  31.       
  32.   
  33. @foreach (var item in Model) {  
  34.       
  35.           
  36.             @Html.DisplayFor(modelItem => item.User.FirstName)  
  37.           
  38.           
  39.             @Html.DisplayFor(modelItem => item.CoursesName)  
  40.           
  41.           
  42.             @Html.DisplayFor(modelItem => item.Topic)  
  43.           
  44.           
  45.             @Html.DisplayFor(modelItem => item.Description)  
  46.           
  47.           
  48.             @Html.DisplayFor(modelItem => item.Content)  
  49.           
  50.           
  51.             @Html.DisplayFor(modelItem => item.CreatedOn)  
  52.           
  53.           
  54.             @Html.ActionLink("Details""Details"new { id=item.TutorialId })  
  55.           
  56.       
  57. }  
  58.   
  59.   
Please help I dont understand the error at all
i ll apriciate any help. 
 

Answers (4)