List View – Session 22


During this session of ASP.NET Core Tutorial, we are going to create a List View to show List of data. In previous sessions we discussed about Dynamic View and Strongly Typed View. In continuation of View topic, we are passing list of object to View with IENumerable interface then restore those data in our View.

What is IENumerable?

IENumerable is an Interface in System.Collections.IEnumerable namespace that has just one method. This method “GetEnumerator()” returns an IEnumerator interface. IEnumerator is based Interface for storing Non-generic collection and generic collection. Stored collection inside IENumerable interface can be navigated with foreach loop.

Create View to Show List of Data

First, for getting data from database or even Static Repository, we should add our method declaration inside our ICostRepository. Also, as we need to store a collection of Cost Model, we use IENumerable as output result.

Second, we should implement this method inside our repository. Since now, we just have one static repository and implement this method inside that one.

After that, we continue with creating an ActionMethod inside CostController for getting data from Repository and passing data collection to View.

Finally, we create List View, and restore the data collection from the Model with foreach loop.

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube and you can have access to list of all sessions HERE.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes


0 0 votes
Article Rating

Inline Feedbacks
View all comments