Setting Visible Disabled with Security Roles

Hi Radzen,
I'm struggling on setting the component "visible"" and "disabled" properties using the Security.IsInRole object.
What is the proper way to do this in the Designer.
I have used the forum to search and have tried the suggestions, it sometimes works for one component and not for an other.
Getting : too many characters (cs1012) and all sorts of errors.

In Navigation items this with one or two options works: but not with 3 options

@Security.IsInRole(new string[]{"XXX","YYYY","ZZZZ"})

also tried this

@Security.IsInRole(new string[]{'XXX','YYYY','ZZZZ'})

Please advice :
PS: using page properties is not a clean solutions with many roles defined.
Regards,
Mehmet

Just tested this and got no errors. Tested with 3 options and more. What is the generated code? What is the exact compilation error?

This won't work because strings in C# need ". Single quotes are for char which are only one character long.

Please test with the Navigation items (menu) :

reproduce:
Create a menu (with no path , to make a sub menu heading)
Create a menu item under the first one .
And put the Security.IsInRole with three Rols in it and you will get an error , with two roles it wil not complain.
Rolenames must be of some length , "ADMIN","Tenantsadmin","Helpdesk" e.g.

The singe quotes I have used with the ${} notation without the @ sign, just to be sure ..

The error is not given right away, I have stopt and run the application again ..

dotnet: D:\Radzen\Blazor\xx\xxx\RadzenAPP\server\Shared\MainLayout.razor(137,75): error RZ9986: Component attributes do not support complex content (mixed C# and markup). Attribute: 'Visible', text: 'Security.IsInRole(new string[]{"MCM","tenantsadmin","Helpdesk"}) ' [D:\Radzen\Blazor\xx\xxx\RadzenAPP\server\RadzenAPP.csproj]

PS: I notice that there is a " " blank- space char at the end of the line with code like:
'Security.IsInRole(new string[]{"MCM","tenantsadmin","Helpdesk"}) '

image

That's what I tested with ...


<RadzenPanelMenuItem Text="Item 0" Visible="@Security.IsInRole(new string[] { "One", "Two", "Three", "Four", "Five"})">
</RadzenPanelMenuItem>

In addition the IsInRole method is declared as params

public bool IsInRole(params string[] roles)

This means you can use it like this:

Security.IsInRole("One", "Two", "Three", "Four", "Five")

Trailing whitespace after the ) may indeed be a problem - delete it if there is any.

1 Like