我希望收到一个字符串,因为视图中的动作链接传递了id。但由于某种原因,我总是得到错误HTTP错误404.0 - 未找到您正在寻找的资源已被删除,其名称已更改,或暂时不可用。当我调试控制器中的删除代码永远不会被执行时,它只会抛出一个错误。我不明白为什么我用以下代码无法实现它。
//action link passing id (string)
<td>
@Html.ActionLink("Delete Room", "Delete", new {id=item.RoomName})|
</td>
//controller method Delete
public ActionResult Delete(string id)
{
Room room = db.Rooms.Find(id);
if (room == null)
{
return HttpNotFound();
}
return View(room);
}
//RouteConfig.cs
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}