From the course: ASP.NET MVC: HTTP Request Life Cycle

Unlock the full course today

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

Solution: Create a custom route

Solution: Create a custom route

From the course: ASP.NET MVC: HTTP Request Life Cycle

Start my 1-month free trial

Solution: Create a custom route

(upbeat intro music) - [Instructor] Let's review the solution to our challenge together. In the exercise files, expand the Roux Academy project and right click on controllers to add a new MVC controller. We'll choose the first option empty controller and the name will be course controller since our route needs to have a core segment in it. Add a new public action method that returns an action result and I'll name it get course details since that describes what it'll do. It accepts a string parameter course name and it's simply returns a content result and I'll hard-code a string that says here are the course details. Remember that we need to map the route course forward slash name of the course forward slash details to this new action method. And the challenge mentioned that we should use a simple approach. So we can do this with attribute routing. Let's add a route attribute above the action method and the URL pattern…

Contents