我知道这可能是直截了当的,但这对我不起作用,我想简单地连接它以在我点击它时触发一个viewController。当我创建一个控制器和一个视图并单击它时,它会抛出404并且代码永远不会到达控制器。
<div><a href="../Admin/AdminReports.aspx"> All Accounts In the System</a></div>
答案 0 :(得分:1)
你可能应该遵循mvc的几个教程。默认情况下使用System.Web.Routing魔法链接(如果您有默认模板,请查看global.asax)。默认网址看起来像/controller/action/id
,其中id是可选的,操作默认为索引,控制器默认为 Home 。对于视图中的链接构造,请使用以下辅助方法:
@Html.ActionLink("All accounts in the system", "AdminReports", "Admin");
或
<a href="@Url.Action("AdminReports", "Admin")">All accounts in the system</a>
该链接应与默认设置/Admin/AdminReports
类似。
答案 1 :(得分:1)
你想要这样的东西:
<a href='<%= Url.Action("Controller", "Action") %>'>Text</a>
,其中
Controller =您的控制器名称。 行动=你的行动方法。