Now we have a category table that has been created inside the database.
So what we want to do is we want to create a new page where we can display all the categories when we
are working with razor pages.
It will be inside the Pages folder as compared to views in MVC.
So instead, pages we have the home page, which is indexed starts HTML.
We want to create pages for listing all the categories, creating category editing category and deleting
category, rather than cluttering everything in one place.
We will create a new folder inside pages.
At the border as categories and in there they create a new razor page.
The first piece that we want to create will be used to display a list of all the categories so we can
name that as index, we will select the reserve page empty here because we want to start with a clean
and empty page rather than working with a template.
So select empty and we then hit add button name off the reserve page.
We're going to keep that at index stops.
Yes, Admiral, let's ask them.
As soon as you add that, you will notice two files were added.
One is this yes file and we have this CDMO, the docs file will be the file where we have page model
index page.
You can see the model that is being referenced here is inside happy web pages, categories index model.
And this particular namespace will be the namespace that you see on top here.
So that is how it is binding everything together, and we have our class index model.
Now we used Entity Framework Code to add migrations to create a category table, which was inside model
and TV context was Application Context Insight program that since we registered that service in our
container, since we have registered the service, whenever we have to access database, we do not have
to create an object of application DB context.
What happens here is the service is already available in the container, so we just need to tell our
container that, hey, I need to use the DB context to access database.
So give me an implementation of this class.
How do you do that?
That will be done using constructor inside this.
Yes, final.
We need to create a read only application DB context, and we look at the using statement I will call
that underscore tbh.
Now we want an implementation of this clause using dependency injection that will create an inside constructor.
So we will type our first tap twice.
This is a snippet to create constructor quickly in.
We still, you know, if you have registered anything inside the container and you want its implementation,
you simply to hear the implementation that you want.
So we get it right, that we want an implementation of application DB context and give that to us in
a variable with the name of DB.
We will assign a private variable, which is underscored the value of TB.
So now what?
Invesco TB will have an implementation that already connects to the database, and we can use that.
Inside the on deck method, we need to retrieve a list of all the categories in order to retrieve that,
we need to create a property that will hold the category list.
So on top here we can create an innumerable on category and let's call that categories.
Next thing that we have to do is we need to populate this categories list.
So this we need to populate from the database.
So we underscored deep and with Entity Framework Code.
When you write DOT here, it will display all of the tables or TV sets that we added.
So if you scroll down here, you should see the category DPI said that, we added.
So we want to retrieve underscored deep dot categories.
This would retrieve all the list of categories.
We did not have to write any fancy sequel like select star from Categories Table.
We did not have to open a connection.
We did not have the close connection.
No cleanup was needed.
Entity framework takes care of everything and we just access deep context.
And then on category, we have multiple methods to create, update, delete and much more.
But if you just say underscore Typekit category, it would automatically fit with all of the categories
and store that in this way, the able.
I get better looks good inside index page model for categories.
Now, what I want to do is inside shed, we have underscored lay out we can navigate to two pages we
have indexed and privacy rather than privacy.
I want to navigate inside the categories folder.
We have the index page.
Since we want to go in the we will not use the forward slash, we can directly say categories and then
forward slash.
What is the page name that is index?
So here we have to use the exact growth that we have in folder structure.
If you were using MVC, you have controllers and action method, but with razor pages, everything is
simple.
Actual way in which the folders are organized will be the exact route, so routing is pretty simple.
Increase our features.
We're going to change the link here to display categories.
And let me see if this run the application.
Right now it is running things using the AP Web profile, but we will change that to Ice Express in
just a second.
But if we go back, we have the categories tab here and you can see that you are all in the bottom left.
It displays the categories.
Let's hit this button and see what happens.
We see an index each year, but no data is displayed.
We don't want to work with data right now.
Let's go to our code behind here.
And let me add a debugging code.
Let's go back and let me just refresh the page.
We hit our break point.
If I press a 10, it will take us to the next line.
And then if we examine what card populated in our categories, it will be empty because we do not have
any records.
So you get no result.
Let me add a great point on this line to the one before.
And let me switch to a sequencer where we can keep our application running.
Actually, I can hit the Continue button to go back.
Inserts sequel server.
Let me expand the database tables.
Let's directly edit the top 200 rows.
Let me create a name test and display either two, so we have one record in our database.
Now if we go back to the application and hit categories one more time, it hits our breakpoint again.
This time we should see one record that is being retrieved and perfect.
We see all the details populated.
So with that, you can see we are successfully able to retrieve all of the records for categories from
database in the next video.
Let's work on displaying these categories inside index page right here.