Entity Framework Code First with MVC : RuntimeBinder Exception error

90 Views Asked by At

I am using ASP.Net Core Web Application with MVC and EF Code First and my db is MySQL. Here is the structure of my db: enter image description here

I am trying to display data from the view bag and its giving me an error. This is index.cshtml

Its complaining about foreach loop.

browser error

here is whats inside viewBag: This is kinda weird. Is it an infinite loop? What is the problem? enter image description here

2

There are 2 best solutions below

2
On

Please remove @ from the starting of @foreach => foreach loop. Hope it works.

0
On

ViewBag.Employees is type of Employee & not EmployeeDate, I'll suggest to cast ViewBag.Employees to respective Datatype & use the same in foreach. It will help you to reduce runtime errors.