2

通常,路由到任何控制器的 Index 操作的 ActionLink 将省略链接中的“Index”,即http://localhost:8080/Controller/id. 就我而言,我试图将字符串作为 ID 传递给 Eta 控制器的 Index 操作。代码如下:

@Html.ActionLink(item.Name, "Index", "Eta", new { id = item.Name }, null)

结果链接显示为:http://localhost:8080/Eta/Index/some-input-string而不是http://localhost:8080/Eta/some-input-string

此 RouteConfig 与 File>New Project>MVC4 Application 完全相同。

4

2 回答 2

3

在 URI 中包含“索引”作为操作是必要的,因为您在字符串中包含路由值。

如果不指定动作,路由值将被解释为动作。

例如:

http://localhost:8080/Etc/abc123
                       ^    ^
                Controller  |
                            |
                        Action (oops)

对你来说,abc123是一个有意义的参数。对于路由引擎来说,这是一个动作。

于 2013-03-25T00:09:54.363 回答
0

MVC4 模板中的标准路由是 {Controller}/{Action}/{id},因此您需要将其更改为 {Controller}/{id},默认 Action = "Index"

于 2013-03-25T00:10:51.660 回答