2013-07-26 2 views
0

나는 다음과 같은 사용자 지정 도우미가 : 내 면도기보기에서 잘 볼 수있다사용자 정의 MVC의 HTMLHelpers

 <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 

을 다음과 같이 사용하려고 오전 :

@Html.ActionLinkAuthorized("Edit", "Edit", "Account", New With {.id = currentItem.Id}, htmlAttributes:=New With {.class = "btn btn-warning", .title = "Edit"}) 

그러나 응용 프로그램을 실행할 때 다음과 같은 오류가 발생합니다.

'(행 193)'값을 'System.Web.Routing.RouteValueDictionary'로 변환 할 수 없습니다.

저는 완전히 VB.NET을 처음 접했고 잘못하고있는 것이 확실하지 않습니다. 어떤 도움이라도 대단히 감사 할 것입니다.

답변

0

RouteValueDictionary가 아닌 Object로 routeValues를 전달합니다. 이에 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 

는 또한, 당신은 당신의보기의 HTML 도우미를 호출 할 때, 인수 이름을 지정할 필요가 없습니다. 사용 :

@Html.ActionLinkAuthorized("Edit", "Edit", "Account", New With {.id = currentItem.Id}, New With {.class = "btn btn-warning", .title = "Edit"}) 
관련 문제