MVC4动态创建ActionLink意外工作

时间:2012-09-09 17:05:57

标签: razor asp.net-mvc-4

我使用的是MVC4和Razor

当我动态创建ActionLink并希望有人可以解释原因时,我得到意想不到的结果:问题是当我将null作为htmlAttribute传递时,URL会正确生成。但是,当我传入一个值时,URL的Area部分就搞乱了。

<li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName, rvd,link.ActionName.Equals(currentAction) && link.ControllerName.Equals(currentController)? new { @class = "currentMenuItem" }:null)</li>

http://localhost:48000/Accounts/Forum/TopicsGrid?Count=2&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D

当我传递null作为htmlAttribute时它的CORRECT:

<li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName, rvd, null)</li>   

http://localhost:48000/Forums/Forum/TopicsGrid/1

1 个答案:

答案 0 :(得分:0)

ActionLink() does not have Dictionary, Object超载 由于您的上一个参数是Object,因此routeValues参数也被解释为objetc,因此它会读取RouteValudDictionary类的属性。

相关问题