Asp.net-Mvc-3
在 Html.BeginForm() 中使用 DELETE 表單方法?
我想盡可能使用適當的 HTTP 方法。在這種情況下,當點擊按鈕刪除某些內容時,我想使用屬性觸發控制器操作
[HttpDelete]。但是,我似乎無法使用這種方法創建表單 - 使用 Razor 語法。FormMethod列舉沒有選項,並且執行以下Delete操作不會覆蓋它:@using (Html.BeginForm("Order", "Users", FormMethod.Post, new { method = "DELETE" }))尋找解決方案一無所獲,沒有人這樣做嗎?我知道我可以只使用 POST 但這不是 HTTP 刪除方法的重點嗎?
你需要在你的表格中:
@using (Html.BeginForm("Order", "Users"){ @Html.HttpMethodOverride(HttpVerbs.Delete) }