Added Route Prefix in Attribute Routing
parent
4dd245cf1f
commit
a4d2fda2a9
|
@ -9,6 +9,7 @@ using AttributeRoutingDemoInMVC.Models;
|
|||
|
||||
namespace AttributeRoutingDemoInMVC.Controllers
|
||||
{
|
||||
[RoutePrefix("students")]
|
||||
public class StudentsController : Controller
|
||||
{
|
||||
private static List<Student> students = new List<Student>()
|
||||
|
@ -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<string> CourseList = new List<string>();
|
||||
|
|
Loading…
Reference in New Issue