Asp.net-Mvc
[AcceptVerbs(HttpVerbs.Post)] 和 [HttpPost] 有什麼區別?
我可以使用 [AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)] 來裝飾動作
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(string title) { // Do Something... }或使用 [HttpPost]/[HttpGet] 屬性
[HttpPost] public ActionResult Create(string title) { // Do Something... }它們不同嗎?
沒有。一個只是另一個的簡寫。
[HttpPost]是 的簡寫[AcceptVerbs(HttpVerbs.Post)]。唯一的區別是你不能[HttpGet, HttpPost]在同一個動作上一起使用(和類似的)。如果您希望某個操作同時響應 GET 和 POST,則必須使用[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)].