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
- @{
- ViewBag.Title = "Index";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
Index
- @Html.ActionLink("Create New", "Create")
-
class="table"> - @Html.Label("Email")
| - @Html.Label("First Name")
| - @Html.Label("Last Name")
| - @Html.Label("Status")
| |
- @foreach (var item in Model) {
- @Html.DisplayFor(modelItem => item.email)
| - @Html.DisplayFor(modelItem => item.first_name)
| - @Html.DisplayFor(modelItem => item.last_name)
| - @Html.DisplayFor(modelItem => item.status)
| - @Html.ActionLink("Details", "Details", new { id = item.id }) |
|
- }
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...
Veerendra AnnigereRank #927 · 2.2K reputationPosted Dec 24, 2019, 12:52 AM EST