我有这个:
public class PagesModel
{
public string ControllerName { get; set; }
public string ActionName { get; set; }
public int PagesCount { get; set; }
public int CurrentPage { get; set; }
public object RouteValues { get; set; }
public object HtmlAttributes { get; set; }
}
public static MvcHtmlString RenderPages(this HtmlHelper helper, PagesModel pages, bool isNextAndPrev = false)
{
//some code
var lastPageSpan = new TagBuilder("span");
var firstValueDictionary = new RouteValueDictionary(pages.RouteValues) { { "page", pages.PagesCount } };
lastPageSpan.InnerHtml = helper.ActionLink(">>", pages.ActionName, pages.ControllerName, firstValueDictionary, pages.HtmlAttributes).ToHtmlString();
return MvcHtmlString.Create(lastPageSpan.ToString());
}
它生成的链接如下所示:<span><a href="/Forums/Thread?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">>></a></span>
为什么?我究竟做错了什么?当我在设置之前设置断点时.innerHtml
,我发现我的firstValueDictionary
外观完全正常。到底是怎么回事?
更新:当我RouteValueDictionary
用新创建的匿名类型(new {page = 0}
)替换参数时,一切正常。为什么我不能使用预定义的RouteValueDictionary
?