jbogard / ContosoUniversity

Contoso University sample re-done the way I would build it
Apache License 2.0
393 stars 131 forks source link

Question: indexer on foreach #36

Closed DominiqueFonteyn closed 5 years ago

DominiqueFonteyn commented 5 years ago

Hi,

I have question about the syntax you used in some of the Index pages. For instance, Course - Index

There is a foreachloop that creates a table row for each Course, but instead of using the itemvariable you use an indexer to access the properties of that Course.

@Html.Display(modelItem => modelItem.Courses[i].CourseID)

What is the reason for doing it like this?

Thanks for helping me out.

jbogard commented 5 years ago

It’s part of a demo around putting unique IDs for table rows for view screens.

On Wed, Mar 6, 2019 at 6:48 AM DominiqueFonteyn notifications@github.com wrote:

Hi,

I have question about the syntax you used in some of the Index pages. For instance, Course - Index https://github.com/jbogard/ContosoUniversity/blob/master/src/ContosoUniversity/Features/Course/Index.cshtml

There is a foreach loop that creates a table row for each Course, but instead of using the item variable you use an indexer to access the properties of that Course.

@Html.Display(modelItem => modelItem.Courses[i].CourseID)

What is the reason for doing it like this?

Thanks for helping me out.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbogard/ContosoUniversity/issues/36, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMpNgOVYpsd5ER6XevIKj66td5B3bks5vT9UpgaJpZM4bhBMc .