c# - 我不能从视图中调用控制器中的操作方法
问题描述
我想从“索引”视图提供的链接上的“主页”控制器调用“删除人员”方法,但得到错误:“找不到此资源”:HTTP 404,URL:/Home/DeletePerson/ 1. 我试过@Html.ActionLink,但它也不起作用。我的错误在哪里?该项目有 .NET Framework 4.7.2、Entity Framework 6.2.0、MVC 5。这个项目有 HomeController:
public class HomeController : Controller
{
...
public ViewResult Index()
{
...
return View("Index");
}
[HttpGet]
public ActionResult DelelePerson(int id)
{
...
return View(person);
}
[HttpPost]
public ActionResult DeletePersonConfirmed(int id)
{
...
return RedirectToAction("Index");
}
}
我的 Index.cshtml 包括
<td><p><a href="/Home/DeletePerson/@b.Id">Del</a></p></td>
解决方案
首先,使用Html.ActionLink
创建正确的链接 他们知道你的具体路由配置。其次,您的链接可能看起来像“/Home/DeletePerson?id=@b.id”,但这取决于您尚未发布的路由配置。
推荐阅读
- php - Laravel - 如何用 builder 上的 where 子句包围所有先前的子句?
- ios - 如何快速监控地点 4
- c# - Sharepoint List 检索大数据 C#
- google-plus - google plus 收藏是否有任何关注按钮?
- java - 易失性变量并刷新到主存储器/从主存储器读取
- unity3d - 是否可以从数据库查询 3D 对象到统一场景?
- vuejs2 - Vue模板中的返回值
- java - org.json.JSONException:仅使用 API 28 在字符 0 处输入结束
- c - 将 strlen 与 scanf(%ms) 一起使用
- ios - 在 Tableview 中对单元格进行分组、在单元格上方或下方添加文本以及空白区域