Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialolu adesina
23,007 Pointswhy are we using @comicBook.DisplayText instead of @Model.DisplayText
When we was inputting properties from our comicbook data model into our detail.cshtml file we used
@model ComicBookGallery1.Models.ComicBook
<h4>@Model.DisplayText</h4>
but here we used
@model ComicBookGallery1.Models.ComicBook[]
<h4>@comicBook.DisplayText</h4>
Why are we not using model.example Steven Parker
1 Answer
Steven Parker
231,198 PointsHi, I was alerted by your tag.
In the second example, the model is no longer a single record, but an array of records. The variable "comicBook" (with lower-case "c") is a single record, taken directly from the model on this line:
@foreach (var comicBook in Model)
So the value is still coming from the model, but now it's done inside of a loop which generates the HTML for each entry one at a time.
olu adesina
23,007 Pointsolu adesina
23,007 Pointsthanks i tested this out by changing the Model name in visual studio and i got and error. this make total sense