Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc razor VB.NET中的自定义MVC HTMLHelper_Asp.net Mvc_Vb.net_Razor_Html Helper - Fatal编程技术网

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"})