post and get with same method signature

前端 未结 7 1930
闹比i
闹比i 2020-12-02 15:39

In my controller I have two actions called \"Friends\". The one that executes depends on whether or not it\'s a \"get\" versus a \"post\".

So my code snippets look s

7条回答
  •  無奈伤痛
    2020-12-02 15:53

    If you truly only want one routine to handle both verbs, try this:

    [AcceptVerbs("Get", "Post")]
    public ActionResult ActionName(string param1, ...)
    {
    //Fun stuff goes here.
    }
    

    One potential caveat: I'm using MVC release 2. Not sure if this was supported in MVC 1. The Intellisense documentation for AcceptVerbs should let you know.

提交回复
热议问题