diff --git a/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj b/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj index 2827d9c..41a33a6 100644 --- a/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj +++ b/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj @@ -172,6 +172,7 @@ + diff --git a/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs b/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs index b9788e2..5d05c21 100644 --- a/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs +++ b/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs @@ -29,16 +29,24 @@ namespace AttributeRoutingDemoInMVC.Controllers } [HttpGet] - [Route("{studentID}")] + [Route("{studentID:int:range(1,3)}")] // This will be translated to /students/2 - public ActionResult GetStudentByID(int studentID) + public ActionResult GetStudentDetails(int studentID) { Student studentDetails = students.FirstOrDefault(s => s.Id == studentID); return View(studentDetails); } [HttpGet] - [Route("students/{studentID}/courses")] + [Route("{studentName:alpha}")] + public ActionResult GetStudentDetails(string studentName) + { + Student studentDetails = students.FirstOrDefault(s => s.Name == studentName); + return View(studentDetails); + } + + [HttpGet] + [Route("{studentID}/courses")] // This will be translated to /students/2/courses public ActionResult GetStudentCourses(int studentID) { diff --git a/AttributeRoutingDemoInMVC/Views/Students/GetStudentDetails.cshtml b/AttributeRoutingDemoInMVC/Views/Students/GetStudentDetails.cshtml new file mode 100644 index 0000000..91d5637 --- /dev/null +++ b/AttributeRoutingDemoInMVC/Views/Students/GetStudentDetails.cshtml @@ -0,0 +1,21 @@ +@model AttributeRoutingDemoInMVC.Models.Student +@{ + ViewBag.Title = "GetStudentDetails"; +} + +

GetStudentDetails

+
+

Student

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+
\ No newline at end of file