From a4d2fda2a9608afa47a0c43f2739befa6eb7510a Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Wed, 16 Jun 2021 15:37:30 +1000 Subject: [PATCH] Added Route Prefix in Attribute Routing --- AttributeRoutingDemoInMVC/Controllers/StudentsController.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs b/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs index a6715e4..69d5989 100644 --- a/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs +++ b/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs @@ -9,6 +9,7 @@ using AttributeRoutingDemoInMVC.Models; namespace AttributeRoutingDemoInMVC.Controllers { + [RoutePrefix("students")] public class StudentsController : Controller { private static List students = new List() @@ -20,12 +21,16 @@ namespace AttributeRoutingDemoInMVC.Controllers }; [HttpGet] + [Route] + // This will be translated to /students public ActionResult GetAllStudents() { return View(students); } [HttpGet] + [Route("{studentID}")] + // This will be translated to /students/2 public ActionResult GetStudentByID(int studentID) { Student studentDetails = students.FirstOrDefault(s => s.Id == studentID); @@ -34,6 +39,7 @@ namespace AttributeRoutingDemoInMVC.Controllers [HttpGet] [Route("students/{studentID}/courses")] + // This will be translated to /students/2/courses public ActionResult GetStudentCourses(int studentID) { List CourseList = new List();