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 KumarPosted Aug 14, 2018, 10:38 PM
Adalat KhanPosted Aug 15, 2018, 5:29 PM
Jignesh KumarPosted Aug 15, 2018, 9:44 AM
Bryian TanPosted Aug 14, 2018, 10:13 PM
Jaish MathewsPosted Aug 14, 2018, 8:59 PM