I have an Action Method in MVC application that retrieves the list of Students from a database table StudentsInfo using LINQ query. When i retrieve all the columns from the table then the Query works but when i try to retrieve some specific columns from the table then i get the following error message:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[<>f__AnonymousType6`1[System.String]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MVCApplication.StudentsInfo]'.
What I have tried:
Following is the action Method
public ActionResult GetAllStudents()
{
//Retrieve data from StudentsInfo table
var result = from d in db.StudentsInfo
select new
{
d.StdRegNumber,
d.StdName,
d.StdDoBirth
};
return View(result.ToList());
}
Thanks in advance


Jignesh KumarRank #91 · 22.9K reputationPosted Aug 14, 2018, 6:38 PM EDT
Jaish MathewsRank #225 · 11K reputationPosted Aug 14, 2018, 4:59 PM EDT
Bryian TanRank #396 · 6.3K reputationPosted Aug 14, 2018, 6:13 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 15, 2018, 5:44 AM EDT
Adalat KhanRank #1,143 · 1.6K reputationPosted Aug 15, 2018, 1:29 PM EDT