title: ASP.NET Identity - Using Roles with JavaScript Functionality
body: <p>I have an application using JQuery DataTables.  I want these tables to display for every user, but only allow the click functionality for users in a specific role.</p>
  
  <p>So, I can set up authorization on the controllers with this...</p>
  
  <pre><code>[Authorize(Roles = "Admin")]
  </code></pre>
  
  <p>That's not enough because there will still be a call to this controller and method and a redirection for those not in the "Admin" role.</p>
  
  <p>Let's say I have a function in my javascript like this...</p>
  
  <pre><code>//Click event on the table row
  $('#table1').on('click', 'tr', function (event) {
      //Post the data to the controller
      $.ajax({
          type: "POST",
          url: "/Controller/Action",
          data: {someData : someData},
          success: function () {
              //do something 
          }
      });
  });
  </code></pre>
  
  <p>I'd like to wrap something around this around the click event...</p>
  
  <pre><code>if (role == "Admin") { //click event in here }
  </code></pre>
  
  <p>Now, I know that the roles are on the server side, while the javascript is on the client side.<br>
  I've seen some suggestions about using razor syntax to output something into a hidden column and then grab that value with the javascript.  Something like this...</p>
  
  <pre><code>@if (User.IsInRole("Admin"))
  {
      &lt;input type="hidden" id="isAdmin" value="true"&gt;
  }
  </code></pre>
  
  <p>But, that's not really secure, because the hidden fields can still be accessed.
  What proper way can I use these identity roles to work with my javascript?</p>