Added Route Prefix in Attribute Routing
parent
4dd245cf1f
commit
a4d2fda2a9
|
@ -9,6 +9,7 @@ using AttributeRoutingDemoInMVC.Models;
|
||||||
|
|
||||||
namespace AttributeRoutingDemoInMVC.Controllers
|
namespace AttributeRoutingDemoInMVC.Controllers
|
||||||
{
|
{
|
||||||
|
[RoutePrefix("students")]
|
||||||
public class StudentsController : Controller
|
public class StudentsController : Controller
|
||||||
{
|
{
|
||||||
private static List<Student> students = new List<Student>()
|
private static List<Student> students = new List<Student>()
|
||||||
|
@ -20,12 +21,16 @@ namespace AttributeRoutingDemoInMVC.Controllers
|
||||||
};
|
};
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[Route]
|
||||||
|
// This will be translated to /students
|
||||||
public ActionResult GetAllStudents()
|
public ActionResult GetAllStudents()
|
||||||
{
|
{
|
||||||
return View(students);
|
return View(students);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[Route("{studentID}")]
|
||||||
|
// This will be translated to /students/2
|
||||||
public ActionResult GetStudentByID(int studentID)
|
public ActionResult GetStudentByID(int studentID)
|
||||||
{
|
{
|
||||||
Student studentDetails = students.FirstOrDefault(s => s.Id == studentID);
|
Student studentDetails = students.FirstOrDefault(s => s.Id == studentID);
|
||||||
|
@ -34,6 +39,7 @@ namespace AttributeRoutingDemoInMVC.Controllers
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("students/{studentID}/courses")]
|
[Route("students/{studentID}/courses")]
|
||||||
|
// This will be translated to /students/2/courses
|
||||||
public ActionResult GetStudentCourses(int studentID)
|
public ActionResult GetStudentCourses(int studentID)
|
||||||
{
|
{
|
||||||
List<string> CourseList = new List<string>();
|
List<string> CourseList = new List<string>();
|
||||||
|
|
Loading…
Reference in New Issue