我想为不同的操作创建一个路由,例如: http://www.example.com/Students
我在StudentController中有一些动作:
[HttpDelete]
public Student DeleteStudent(int id)
[HttpPost]
public int AddStudent(StudentInfo student)
[HttpPut]
public bool UpdateStudent(StudentInfo student)
我想创建一个路由,根据请求的Http方法确定将调用哪个动作。
因此,当用户通过Post方法调用http://www.example.com/Students时,它将是AddStudent
答案 0 :(得分:0)
试试这个
// 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();
}