1

我的一个观点中有这个 ActionLink

Html.ActionLink(pop.PopName, "ShowAllEncounters", "Encounter", new {popId = pop.populationID })

我在想这会带我去正确的路线......
但我却去了这条路线......

http://localhost:19283/Population/ShowAllEncounters?Length=9

路线应该是

http://localhost:19283/Encounter/ShowAllEncounters?Length=9

我查看了我的 global.asax 文件,一切似乎都很正常...除了设置默认打开页面之外,我没有以任何方式更改默认路由...

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Population", action = "PopulationInfo", id = UrlParameter.Optional } // Parameter defaults
        );

这是我所期望的......这类似于我拥有的 MVC3 路线。我在用我的路线做一些时髦的事情吗?我在这里想念什么?

4

2 回答 2

1

看起来你调用了错误的方法重载:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    Object routeValues,
    Object htmlAttributes
)

http://msdn.microsoft.com/en-us/library/dd492124.aspx

相反,请尝试调用此重载:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    Object routeValues,
    Object htmlAttributes
)

http://msdn.microsoft.com/en-us/library/dd504972.aspx


要调用正确的重载,请使用类似于以下内容的内容:

Html.ActionLink(pop.PopName,
                "ShowAllEncounters",
                "Encounter",
                null,
                new {popId = pop.populationID })
于 2012-05-22T17:32:14.303 回答
0

你的代码

Html.ActionLink(pop.PopName, "ShowAllEncounters", "Encounter", new {popId = pop.populationID })

应该

Html.ActionLink(pop.PopName, "ShowAllEncounters", new {controller="Encounter"}, new {popId = pop.populationID })
于 2012-08-10T17:45:37.823 回答