ASP MVC3 - ActionLink无法正确路由到控制器

时间:2013-04-04 23:47:02

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-2

下面是我在ASP MVC3视图中使用的操作链接。我需要控制器中的方法并发送两个变量。这些变量充当控制器方法试图从中提取信息的SQL表上的复合键。

链接似乎由@Html.ActionLink正确呈现,但我收到此错误:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /BankListMasterController/AgentEdit/11

这是行动链接

@Html.ActionLink("Edit Agent", "AgentEdit", "BankListMasterController",
                                            new { agentId = int.Parse(item.AgentId), id = item.ID }, null)

这是控制器方法

    public ViewResult AgentEdit(int id, int agentId)
    {
        string compare = agentId.ToString();

        BankListAgentId agent = (from c in db.BankListAgentId
                                 where c.ID == id &&
                                       c.AgentId.Equals(compare)
                                 select c).Single();

        return View("AgentEdit", agent);
    }

,这是在原始视图中呈现的URL

http://localhost:2574/BankListMasterController/AgentEdit/11?agentId=5309721

我还在方法的第一行放了一个断点,它在调试时永远不会被触发。

1 个答案:

答案 0 :(得分:1)

您不需要在第三个参数中包含“controller”。

尝试:

@Html.ActionLink("Edit Agent", "AgentEdit", "BankListMaster", new { agentId = int.Parse(item.AgentId), id = item.ID }, null)