【发布时间】:2014-07-17 14:55:18
【问题描述】:
我是 MVC 新手,但还没有找到方法。
在视图中我有这个克隆按钮:
<a href="@Url.Action("Clone", "Game", new { pModelId = Model.Id })" class="btn btn-default btn-xs">
<i class="fa fa-plus"></i>Clone Game</a>
在我的控制器中:
[HttpPost]
public ActionResult Clone(int pGameId)
{
int lClonedGameId = mGameRepository.CloneGame(pGameId);
return RedirectToAction("Show", new { id = lClonedGameId, message = "Your game was cloned succesfully" });
}
由于 [HttpPost],我得到了 404,但我不想让它成为 [HttpGet],因为它会写入数据库。有没有办法让那个按钮在没有 BeginForm 或类似的东西的情况下转到 HttpPost 方法?
【问题讨论】:
-
链接总是意味着 GET 请求。如果您希望浏览器发出 POST 请求,则需要一个表单。您使用 MVC 的事实没有任何区别。
标签: asp.net-mvc http-post