MVC5 ActionLink错误的URL

时间:2015-01-13 18:05:01

标签: c# asp.net-mvc-5 actionlink

我试过找到与我的问题类似的东西,但我很难过。我试图将数据从我的视图传递到控制器,但是我收到了错误的URL。从我所知道的路线不是问题,但我不知道是什么。

这是我的代码:

@Html.ActionLink("Add", "Create", "Test", null, new { data_modal = "", id = 1, @class = "btn btn-small btn-primary pull-right" })

我的路由设置:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

以下是发送的链接:

http://localhost:49633/Test/Create?_=1421171966639

我无法弄清楚为什么会这样。我从Home,Index视图中的视图传递给控制器​​,"测试" ...这是一个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

由于您需要链接中的id,因此需要将id作为路由值传递,如:

@Html.ActionLink("Add", "Create", "Test", new {id = 1}, { data_modal = "", @class = "btn btn-small btn-primary pull-right" })