Hey guys.
So this suit will go about adding our enrollments to our students detail page.
No.
An enrollment in fewer recall in our database comprises a student's I.T..
And of course I.T..
This serves to link a student to of course which means that you have many students being linked to many
courses.
The objective behind this is to ensure that when we click on the details page of a student we will see
that this student is currently actively enrolled in X Y Z courses no as a quick recap.
We know that we did our scaffolding exercise for our students and so we can create a new one in its
view details and delete.
Now if I click the Details button it will trigger a call to our action in our students controller.
I set a breakpoint and I'm currently in debug mode and we just want to take a look at the object that
comes back when we click details.
So we're going to feature students and the idea that was passed in was two thousand and two and we can
see that on was fetched because we did not get back an empty object.
Now when we look in this object we see that we have first name last name middle name and we also have
two enrollments so this student is currently associated with two courses in our enrollments table and
which would quickly come out of debug mode and we take a look at our database to validate that clear.
So in my object explore I'm just going to right click force and look at data.
And here we have three courses Introduction to the C sharpies mining calculus and enrolments we can
see that we have students with the I.D. two thousand and two enrolled to both courses with I.D. two
and three.
I'm not going to commit those to memory and obviously showing this to a human really does not work.
So now we're going to see how entity framework makes it easy for us the data bind and display data that
is not directly in our table inside of our view.
So here we have our details view for the students and I'm just going to add some information to it's
on censuses student details and I'll leave everything else as is.
And underneath this last Dynamic link tag I'm going to start populating it with some code that is going
to generate a table showing all of the enrollments for this students.
Now this table is going to look rather similar to the one that we're used to from our index page.
If you recall our index page has a table it has a top row with some headers and then it has a piece
of code that is generating rows and columns based on the data coming back inside that model.
Now we do have a model being passed into our details.
But unlike our index page it is not our collection.
It does however have a collection property in it in the form of enrollments which is what we just saw
in debug mode in our students controller.
So we're going to go about creating a table that will furnish rows and columns based on the data coming
back from our enrollments collection.
The first thing we need is our table and since we're using Bootstrap we can quickly me at this table
look attractive by just adding a few tables classes size table and then I want it to be condensed as
well as responsive.
Next we generate our topmost rule which will have our table headers.
So for our table headers I want the course title and I'm just going to control these and duplicate these
and I would like the credits.
I'm not sure if I need to sell or remove this makes those who want to utilize our reserve view and start
dynamically generating rows according to what comes back in our enrollments property.
So I want to use my sign and write the word for each open that's open we want var something I can file
it enrollment in and then we have a keyword in C sharp called model.
No this keyword embodies whatever data comes back inside of this model and it starts with a capital
M someone's rights.
Capital M model dot.
And we're going to see our enrollments which if we look at the data carefully we see it is a collection
type so for each of these I'm going to generate a rule so t are.
And in this rule I want to follows and I'm just going to duplicate that inside this column.
I always say that I don't like printing text without a tag.
So I do a splitting whatever is going to go into this column instead of a PITA.
And then I can just directly reference the enrollment using my at sign enrollment which is no my object
of type enrollment.
So an enrollment object will furnish the course the course I.T. enrollment I.D. the grade the students
and students.
So I'm going to say.
Course since I want the course title I have to get it from the course object.
So I go into the course object then use my dot operator once again and then I will be able to get the
title I'll do the same for the next one and I will add enrollment dot course Dot's critics at the end
of this exercise what we will have is a table being generated with all of these attributes with two
columns one for course title 1 for credits and all of the related data for human readability so we can
go ahead and go into debug mode and see our work no one our page loads we can see quite clearly the
fruits of our labor that our table with our headers and we have human readable data being displayed.
So instead of displaying just the ideas and instead of me having to go and write in our joints to get
the actual data into the framework made it quite easy for us to just call on the data on demand.
No I left out a column because the student knows what they're enrolled in but they do not know their
grades.
So I'm just going to head back over to Visual Studio and modify or view and I'm going to add a column
for grades so I duplicated predicts and I'm just going to say creates or green and then I'm going to
add another column inside this rule which is going to have the corresponding grid data now greed is
inside of the enrollment model.
So once I see enrollment then I have the property grade so I don't need to go into student or go into
course I can just get grid right there from enrollments see this refresh and we will see our changes
and there we go.
So this student is fresh.
They haven't gotten any grades as yet but they see what courses they're doing.
And anybody who stumbles upon their profile will also see what courses they are doing.
So this is a really quick way to get additional data into your view.
I hope you understand the concept.
And once you have a relationship you can either call on the collection of related data or call directly
on the related data so you can go ahead and scuffled an enrollment situation and start creating enrollments
where you associate students with courses and you can view the details of the enrollment with the course
details as well as the student details.
Are watching and I hope you have a good one.