在MVC中使用Post向服务器提交数据时Action还可以这样写:
public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Album album = db.Albums.Find(id); if (album == null) { return HttpNotFound(); } return View(album); } // POST: Albums/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { Album album = db.Albums.Find(id); db.Albums.Remove(album); db.SaveChanges(); return RedirectToAction("Index"); }
在这之中,作为POST提交的方法名称可以随意写,但只需在方法头上面加上[HttpPost,ActionName("XXX")]就行了
转载于:https://blog.51cto.com/xyh1993/1830646