Asp.net mvc razor VB.NET中的自定义MVC HTMLHelper
我有以下自定义帮助程序:Asp.net mvc razor VB.NET中的自定义MVC HTMLHelper,asp.net-mvc,vb.net,razor,html-helper,Asp.net Mvc,Vb.net,Razor,Html Helper,我有以下自定义帮助程序: <Extension> _ Public Function ActionLinkAuthorized(htmlHelper As HtmlHelper, linkText As String, actionName As String, controllerName As String, routeValues As RouteValueDictionary, htmlAttributes As IDictionary(Of Stri
<Extension> _
Public Function ActionLinkAuthorized(htmlHelper As HtmlHelper, linkText As String, actionName As String, controllerName As String, routeValues As RouteValueDictionary, htmlAttributes As IDictionary(Of String, Object)) As MvcHtmlString
If (Roles.IsUserInRole("Administrator")) Then
Return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes)
Else
Return MvcHtmlString.Empty
End If
End Function
但在运行应用程序时,我遇到以下错误:
类型为“(第193行)”的值无法转换为“System.Web.Routing.RouteValueDictionary”
我对VB.NET完全陌生,不太清楚自己做错了什么。任何帮助都将不胜感激。您将routeValues作为对象传递,而不是作为RouteValueDictionary传递。将html帮助程序更改为:
<Extension> _
Public Function ActionLinkAuthorized(htmlHelper As HtmlHelper, linkText As String, actionName As String, controllerName As String, routeValues As Object, htmlAttributes As Object) As MvcHtmlString
If (Roles.IsUserInRole("Administrator")) Then
Return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes)
Else
Return MvcHtmlString.Empty
End If
End Function
<Extension> _
Public Function ActionLinkAuthorized(htmlHelper As HtmlHelper, linkText As String, actionName As String, controllerName As String, routeValues As Object, htmlAttributes As Object) As MvcHtmlString
If (Roles.IsUserInRole("Administrator")) Then
Return htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes)
Else
Return MvcHtmlString.Empty
End If
End Function
@Html.ActionLinkAuthorized("Edit", "Edit", "Account", New With {.id = currentItem.Id}, New With {.class = "btn btn-warning", .title = "Edit"})