diff --git a/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj b/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj index 2a2797e..2827d9c 100644 --- a/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj +++ b/AttributeRoutingDemoInMVC/AttributeRoutingDemoInMVC.csproj @@ -126,6 +126,7 @@ Global.asax + @@ -170,6 +171,7 @@ + diff --git a/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs b/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs index 69d5989..b9788e2 100644 --- a/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs +++ b/AttributeRoutingDemoInMVC/Controllers/StudentsController.cs @@ -54,5 +54,19 @@ namespace AttributeRoutingDemoInMVC.Controllers ViewBag.CourseList = CourseList; return View(); } + + [Route("~/tech/teachers")] + // This will be translated to /tech/teachers + public ActionResult GetTeachers() + { + List teachers = new List() + { + new Teacher() {Id = 1, Name = "James"}, + new Teacher() {Id = 2, Name = "Patrik"}, + new Teacher() {Id = 3, Name = "Smith"} + }; + return View(teachers); + } + } } \ No newline at end of file diff --git a/AttributeRoutingDemoInMVC/Models/Teacher.cs b/AttributeRoutingDemoInMVC/Models/Teacher.cs new file mode 100644 index 0000000..fb9a7e8 --- /dev/null +++ b/AttributeRoutingDemoInMVC/Models/Teacher.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace AttributeRoutingDemoInMVC.Models +{ + public class Teacher + { + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/AttributeRoutingDemoInMVC/Views/Students/GetTeachers.cshtml b/AttributeRoutingDemoInMVC/Views/Students/GetTeachers.cshtml new file mode 100644 index 0000000..4158d3a --- /dev/null +++ b/AttributeRoutingDemoInMVC/Views/Students/GetTeachers.cshtml @@ -0,0 +1,28 @@ + +@model IEnumerable +@{ + ViewBag.Title = "Get Teachers"; +} + +

GetTachers

+ + + + @Html.DisplayNameFor(model => model.Id) + + + @Html.DisplayNameFor(model => model.Name) + + + @foreach (var item in Model) + { + + + @Html.DisplayFor(modelItem => item.Id) + + + @Html.DisplayFor(modelItem => item.Name) + + + } + \ No newline at end of file