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
- @model IEnumerable<Projectname.Models.user>
- @{
- ViewBag.Title = "Index";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <h2>Index</h2>
- <p>
- @Html.ActionLink("Create New", "Create")
- </p>
- <table class="table">
- <tr>
- <th>
- @Html.Label("Email")
- </th>
- <th>
- @Html.Label("First Name")
- </th>
- <th>
- @Html.Label("Last Name")
- </th>
- <th>
- @Html.Label("Status")
- </th>
- <th></th>
- </tr>
- @foreach (var item in Model) {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.email)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.first_name)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.last_name)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.status)
- </td>
- <td>
- @Html.ActionLink("Details", "Details", new { id = item.id }) |
- </td>
- </tr>
- }
- </table>
This is my controller method
- public ActionResult Index()
- {
- var users = (from p in dBModels.users
- join f in dBModels.auth_assignment.Where(x => x.item_name == "Customer")
- on p.id equals f.user_id
- select new
- {
- id = p.id,
- first_name = p.first_name,
- last_name = p.last_name,
- status = p.status
- }).ToList();
- return View(users);
- }
Kindly give proper answer to resolve this issue asap...