I'm having difficulties figuring out how to solve this error message:
Error CS1579 foreach statement cannot operate on variables of type 'A1.Models.Reviews' because 'A1.Models.Reviews' does not contain a public definition for 'GetEnumerator' A1..NETCoreApp,Version=v1.0
@foreach (var item in Model)
<hr id="ReviewsSide" />
<h6><b>@ @Html.DisplayFor(ModelItem => item.Heading)</b></h6>
int numStars = 0;
if (item.Rating == 5)
numStars = 5;
else if (item.Rating == 4)
numStars = 4;
else if (item.Rating == 3)
numStars = 3;
else if (item.Rating == 2)
numStars = 2;
numStars = 1;
for (int i = 0; i < numStars; i++)
<span style="color: #f8bd08; ">★</span>
for (int i = 0; i < 5 - numStars; i++)
You need to replace
IEnumerable<A1.Models.Reviews> @model Reviews
In order to pass a sequence of reviews to your Razor View And be able to iterate over it.
The error shown means that the type being passed is not a sequence and though you can't iterate over it.
With that being said, you need also to make sure that you're passing a sequence from your controller to your View, so that these 3 parts work without any problem.