【发布时间】:2020-07-14 12:57:57
【问题描述】:
当我在 .vbhtml 视图中使用 htmlAttributes 调用 @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&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&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 方法总是返回一个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。
有什么想法吗?
【问题讨论】:
标签: asp.net-mvc vb.net razor asp.net-ajax actionlink