传递 htmlAttributes 时在 MVC 中使用 @Ajax.ActionLink 时出现问题

Problem using @Ajax.ActionLink in MVC when passing the htmlAttributes

当我使用 htmlAttributes:

在我的 .vbhtml 视图中调用 @Ajax.ActionLink
    @Ajax.ActionLink("LinkText", 
                     "Action",
                     routeValues:=baseController.PathParams(New With {.id = Model.Icodciud}), 
                     ajaxOptions:=New AjaxOptions() With {.HttpMethod = "POST", .UpdateTargetId = "myPanel", .InsertionMode = InsertionMode.InsertBefore},
                     htmlAttributes:=New With {.class = "btn btn-primary"})

页面中的结果是这个:

<a class="btn btn-primary" data-ajax="true" data-ajax-method="POST" data-ajax-mode="before" data-ajax-update="#myPanel" 
href="/Controller/Action?Count=2&amp;Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&amp;Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D">LinkText</a>

但是如果我删除 htmlAttributes 参数:

@Ajax.ActionLink("LinkText", 
                 "Action",
                 routeValues:=baseController.PathParams(New With {.id = Model.Id}), 
                 ajaxOptions:=New AjaxOptions() With {.HttpMethod = "POST", .UpdateTargetId = "myPanel", .InsertionMode = InsertionMode.InsertBefore})

那么结果就是这个(效果不错):

<a data-ajax="true" data-ajax-method="POST" data-ajax-mode="before" data-ajax-update="#myPanel" 
href="/Controller/Action?Id=1&Other=Params">LinkText</a>

baseController.PathParams方法总是returns一个RouteValueDictionary:

    Public Function PathParams(Optional params As Object = Nothing) As RouteValueDictionary

        Dim dictionary As IDictionary(Of String, Object) = New Dictionary(Of String, Object)()

     ... some code ...

        Return New RouteValueDictionary(dictionary)

    End Function

所以这不可能是问题所在。问题是当我使用 htmlAttributes 或不使用时。

有什么想法吗?

我发现了问题,如果您想将 ActionLink 方法与 routeValues 一起用作 RouteValueDictionary,那么 htmlAttributes 应该是 IDictionary

Public Shared Function ActionLink(ajaxHelper As AjaxHelper, linkText As String, actionName As String, routeValues As Object, ajaxOptions As AjaxOptions, htmlAttributes As Object) As MvcHtmlString

Public Shared Function ActionLink(ajaxHelper As AjaxHelper, linkText As String, actionName As String, routeValues As RouteValueDictionary, ajaxOptions As AjaxOptions, htmlAttributes As IDictionary(Of String, Object)) As MvcHtmlString