Getting ready

Open up the StudentController class and modify it to contain attribute-based routing. Be sure to add the using Microsoft.AspNetCore.Mvc; namespace to the StudentController class. Also, inherit from the Controller base class.

[Route("Student")]public class StudentController : Controller{   [Route("Find")]   public string Find()   {      return "Found students";   }}

Then, add another folder to your project called Models. Inside the Models folder, add a class called Student because our application will be returning student information. This will be a simple class with properties for the student number, first name, and last name. Your Student class should look as follows:

public class Student{   public int StudentNumber { get; set; } public ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.