i have the following code in my _Layout.cshtml file. The idea is that in my javascript code some items about the security are filled in. LoggedIn and username are obviously no problem, but the way the roles are put in the javascript is wrong. The Roles is simply a string[] (that should become a JSON array.
But it shows as a '[& quot;user& quot;,& quot;'admin& quot;]' which obviously is not a valid JSON array. Any ideas how i can convert my string array to a valid JSON array? My code of the RolesArray is added below.
<script type="text/javascript"> $(function () { require(['jquery','config', 'security'], function ($, config, security) { security.items.loggedIn = '@Request.IsAuthenticated'; security.items.Username = '@User.Identity.Name'; var one = '@((MyIdentity)User.Identity).RolesArray' $(document).trigger("security_changed"); }); }); </script> public String[] RolesArray { get { var two = Roles.ToArray(); return two; } }