Samir Bhogayta

Samir Bhogayta

  • 674
  • 1.4k
  • 813.1k

Need solution for this error.

Dec 24 2019 3:31 AM
I am getting this error :
 
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[<>f__AnonymousType1`4[System.Int64,System.String,System.String,System.Int16]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Projectname.Models.user]'.
 
Here is my code of View
  1. @model IEnumerable<Projectname.Models.user>  
  2. @{  
  3. ViewBag.Title = "Index";  
  4. Layout = "~/Views/Shared/_Layout.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.Label("Email")  
  14. </th>  
  15. <th>  
  16. @Html.Label("First Name")  
  17. </th>  
  18. <th>  
  19. @Html.Label("Last Name")  
  20. </th>  
  21. <th>  
  22. @Html.Label("Status")  
  23. </th>  
  24. <th></th>  
  25. </tr>  
  26. @foreach (var item in Model) {  
  27. <tr>  
  28. <td>  
  29. @Html.DisplayFor(modelItem => item.email)  
  30. </td>  
  31. <td>  
  32. @Html.DisplayFor(modelItem => item.first_name)  
  33. </td>  
  34. <td>  
  35. @Html.DisplayFor(modelItem => item.last_name)  
  36. </td>  
  37. <td>  
  38. @Html.DisplayFor(modelItem => item.status)  
  39. </td>  
  40. <td>  
  41. @Html.ActionLink("Details""Details"new { id = item.id }) |  
  42. </td>  
  43. </tr>  
  44. }  
  45. </table>  
This is my controller method
  1. public ActionResult Index()  
  2. {  
  3. var users = (from p in dBModels.users  
  4. join f in dBModels.auth_assignment.Where(x => x.item_name == "Customer")  
  5. on p.id equals f.user_id  
  6. select new  
  7. {  
  8. id = p.id,  
  9. first_name = p.first_name,  
  10. last_name = p.last_name,  
  11. status = p.status  
  12. }).ToList();  
  13. return View(users);  
  14. }  
Kindly give proper answer to resolve this issue asap...

Answers (9)