I want to create one route for different actions for example: http://www.example.com/Students
I have some action in StudentController:
[HttpDelete]
public Student DeleteStudent(int id)
[HttpPost]
public int AddStudent(StudentInfo student)
[HttpPut]
public bool UpdateStudent(StudentInfo student)
I want to create a route which determine what action will be called based on Http method of request.
So when user call http://www.example.com/Students by Post method, It will be AddStudent
Try this
// Get:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Students()
{
// do some stuff
return View();
}
// Post:
[ActionName("Students")]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Students_Post()
{
// do some stuff
return View();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.