是否可以为post和get提供重复的动作名称和参数列表?

new*_*_86 6 asp.net-mvc asp.net-mvc-3

是否可以有2个具有相同名称和参数的动作,但一个是帖子,另一个是get?例如Delete(id),[HttpPost]Delete(id)...我得到一个错误,说这是不允许的......

fre*_*nky 7

是的,这是可能的.只需在一个操作上使用ActionName属性:

        public ActionResult Delete(int id)
        {
            //...
            return View();
        }

        [HttpPost]
        [ActionName("Delete")]
        public ActionResult Delete_Post(int id)
        {
            //...
            return View();
        }
Run Code Online (Sandbox Code Playgroud)