MVC路线问题

时间:2013-08-11 09:37:06

标签: asp.net-mvc routes

我有以下问题。路线看起来像这样:

        routes.MapRoute(
            "Test",
            "{controller}/{action}/{test}",
            new { controller = "Home", action = "Test" }
        );

在我的控制器中,我有这种方法:

    public void Test(string testParam)
    {

    }

在我看来,我有以下代码:

@Html.ActionLink("Test","Test", new { testParam = "bla"} )

我认为点击链接后我的url应如下所示:

...Home/Test/bla

但事实并非如此,url看起来像这样:

...Home/Test?testParam=bla
在RouteData中

我没有testParam作为键或值...我只有控制器和动作。并且我在RouteData / Route i中有以下目标url controller / action / id,这是错误的路由

in RouteData i do not have testParam as key or value...i only have controller and action. And im RouteData/Route i have following target url controller/action/id

1 个答案:

答案 0 :(得分:1)

将路线改为

routes.MapRoute(
    "Test",
    "{controller}/{action}/{test}/{testparam}",
    new { controller = "Home", action = "Test", testparam = UrlParameter.Optional  }
);