post and get with same method signature

前端 未结 7 1931
闹比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:59

    not entirely sure if it is the correct way, but i would use a meaningless parameter to differentiate the sigs. like:

    // Get:
    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Friends(bool isGet)
    {
        // do some stuff
        return View();
    }
    
    // Post:
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Friends()
    {
        // do some stuff
        return View();
    }
    

    I know it's ugly and hackish, but it works.

提交回复
热议问题