ActionLink无法按预期工作

时间:2013-09-05 12:24:30

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

我正在传递empid,我希望它显示在url中,但它显示为querystring:

<li>@Html.ActionLink(key.Value, "Attendance","HOD",  new {empid=key.Key}, null) 
                                                                           </li>

我想要显示的链接如下:

 /HOD/Attendance/xyz%2Fabc

但它显示我这样:

/HOD/Attendance?empid=xyz%2Fabc //it's like query string but i don't want that.

有人可以帮忙吗?我很感激任何帮助。非常感谢。

我已将此RouteMap添加到Global.asax

routes.MapRoute (
     "HOD_AttByEmpID", // Route name
     "{controller}/{action}/{empid}", // URL with parameters
     new { controller = "Account", action = "LogOn", 
                                    empid = UrlParameter.Optional }             
);

2 个答案:

答案 0 :(得分:2)

你尝试过这样的吗?

@Html.ActionLink(key.Value, "Attendance","HOD",  new { key.Key},null)

来源:HTML.ActionLink method

答案 1 :(得分:1)

我想这是因为你的价值包含'/'

也许你可以试试:

<li>@Html.ActionLink(key.Value, "Attendance","HOD",
         new {empid=Server.UrlEncode(key.Key)}, null) 
</li>