Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# ASP.NET MVC Basics Adding a List Page Finishing the List View

olu adesina
olu adesina
23,007 Points

why 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
Steven Parker
220,425 Points

:bell: Hi, 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
olu adesina
23,007 Points

thanks i tested this out by changing the Model name in visual studio and i got and error. this make total sense