I have to retrieve a collection of objects from table using loop. But I got an error that
The model item passed into the dictionary is of type 'ThaniyamBank.Models.Board', but this dictionary requires a model item of type 'System.Collections.Generic.List`1[A.Models.Board]'
Why this error is coming ? How can I solve this error ?Should I need to change my query ?
controller
public ActionResult Board()
{
var res = db.Boards.Select(t => new
{
Id = t.Id,
Name = t.Name,
Designation = t.Designation,
Phone = t.Phone
}).ToList();
return View(res);
}
view
@model List<A.Models.Board>
@for (var j = 0; j < Model.Count(); j++)
{
<tr>
<td>
@Html.HiddenFor(m => m[j].Id)
@Html.HiddenFor(m => m[j].Name)
@Html.DisplayFor(m => m[j].Designation)
@Html.DisplayFor(m => m[j].Phone)
</td>
</tr>
}
model class
public partial class Board
{
public int Id { get; set; }
public string Name { get; set; }
public string Designation { get; set; }
public string Phone { get; set; }
public string PhotoUrl { get; set; }
}
I need to get the name , designation, and phone of all the peoples in the Board but i am getting an error that .
How can I fix this error?
How to retrieve a collection of data from table ??