C# 在同一控制器中使用Get和Post

C# 在同一控制器中使用Get和Post,c#,asp.net-mvc,visual-studio,C#,Asp.net Mvc,Visual Studio,我想对一个操作方法使用HttpGet和HttpPost属性。但是,我只看到在单独的操作方法中单独使用属性的示例 例如: public ActionResult Index() { //Code... return View(); } [HttpPost] public ActionResult Index(FormCollection form) { //Code... return Vie

我想对一个操作方法使用HttpGet和HttpPost属性。但是,我只看到在单独的操作方法中单独使用属性的示例

例如:

public ActionResult Index()
    {
        //Code...
        return View();
    }

    [HttpPost]
    public ActionResult Index(FormCollection form)
    {
        //Code...
        return View();
    }
我想要这样的东西:

[HttpGet][HttpPost]
public ActionResult Index(FormCollection form)
{
    //Code...
    return View();
}

我记得在某个地方见过这样做,但不记得在哪里做过。

如果您真的想这样做,可以使用
[AcceptVerbs]
属性。(见附件)

这样,您的方法可以处理GET和POST动词(但不能处理其他动词,如PUT)

如果您希望您的方法处理所有谓词,请不要使用任何属性:

public ActionResult Index(FormCollection form)
{
    //Code...
    return View();
}
谢谢这是我想要的(y)
public ActionResult Index(FormCollection form)
{
    //Code...
    return View();
}