0

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

AlecTech
  • 63
  • 8

2 Answers2

0

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

  • sorry forgot to mention this code is inside .cshtml, it requires @foreach, if i remove @ it thinks its not a code. – AlecTech Nov 23 '20 at 21:49
  • @AlecTech you are using the `@foreach` inside the `@if` so there is no need to add `@` infront of foreach. Please try it will resolve the issue. – Jatin Kamboj Nov 25 '20 at 07:34
0

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.