post and get with same method signature

前端 未结 7 1900
闹比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 16:08

    Marking cagdas' response as the answer since it answered my question. However, since I don't like using the ActionName attribute in my project I use a different solution. I simply added the FormCollection to the "post" action (which ends up changing the method signature)

    // Get:
    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Friends()
    {
        // do some stuff
        return View();
    }
    
    // Post:
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Friends(FormCollection form)
    {
        // do some stuff
        return View();
    }
    
    0 讨论(0)
提交回复
热议问题