【发布时间】:2011-10-05 03:57:00
【问题描述】:
我有一个博客。在它的主页上有一个主题列表。我想创建一个按钮,允许用户删除主题(我知道列表中每个主题的 ID,并且该 ID 是数据库中的关键字段)。
视图/主页/索引:
@{
if (ViewBag.userIsModerator)
using (Html.BeginForm("DeleteTopic", "Home", new { topicId = item.ID }))
{
<input type = "submit" value = "Delete topic" />
}
}
点击提交后会启动以下流程。
控制器/HomeController:
[HttpPost]
public ActionResult DeleteTopic(int topicId)
{
db.DeleteTopic(topicId);
return RedirectToAction("Index", "Home");
}
我的问题是将主题的 ID 传递给控制器,因为 new { topicId = item.ID } 是错误的来源。有谁知道,如何在没有 new { topicId = item.ID } 的情况下解决这个问题?
【问题讨论】:
标签: asp.net-mvc-3 razor