【发布时间】:2014-04-08 06:23:10
【问题描述】:
我正在使用 MVC3。我了解到使用 HttpGet 方法删除项目是一种不好的做法,因为任何人都可以浏览到 url 并删除项目。所以我想对HttpPost Method进行删除操作。
问题是当我点击删除按钮时,它只在 HttpGet 方法上被击中,而不是在 HttpPost 方法上。
我使用过 webgrid 及其 index.cshtml 文件
<div id="DataTable">
@grid.GetHtml(htmlAttributes: new {id="gvMovies" },
columns:grid.Columns(
grid.Column("Title","Movie Title",canSort:true),
grid.Column("Director","Film Maker",canSort:false),
grid.Column(header:"Action",
format:@<text>
<a href="@Url.Action("Edit", "Movies", new { id = @item.Id })">Edit</a>
@using (Html.BeginForm("Delete", "Movies", new { id = @item.id }, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ActionLink("Delete", "Delete", new { id = @item.id }, new { onclick = "return confirm('Are you sure you wish to delete this article?');" })
}
</text>)))
</div>
控制器页面如下
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id)
{
return RedirectToAction("Index");
}
【问题讨论】:
标签: c# asp.net-mvc-3 http-post http-get