From the course: Learning ASP.NET

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Course details

Solution: Course details

From the course: Learning ASP.NET

Start my 1-month free trial

Solution: Course details

(dramatic music) - [Narrator] Let's review the solution to our challenge together. I've got the MVC application expanded, and the course controller open. You might have noticed that there's already a details action with some boilerplate code. This is where we'll add logic to retrieve a course by its ID and we can do that with link. Let's declare a course variable and we'll set that to the result of our query. I'm going to use a method based link query but you can also use declarative syntax to get the same result. So starting off with the database context, I can access the course's property and use the where extension method to specify a filter. The filter condition will be where the course ID is equal to the ID parameter passed in. And to execute the query, I'll use single or default, because we expect to have only a single record with that ID otherwise it'll throw an exception and the default value is no if…

Contents