title: Passing an array into a data-attribute in ASP.NET Core
body: <p>I am trying to pass an array of integers into a data-attribute in ASP.NET Core and I can't get it to work.</p>
  
  <p>Here's what I'm trying to do :</p>
  
  <p><strong>Controller :</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>public class HomeController : Controller
  {
      public IActionResult Index(){
          int[] t = {1, 2, 3, 4};
          ViewBag.t = t;
          return View();
      }
  }
  </code></pre>
  
  <p><strong>Razor View :</strong>
  </p>
  
  <pre><code>@{
      ViewData["Title"] = "Home Page";
  }
  
  &lt;label id="intLabel" data-int-array="@(ViewBag.t)"&gt;My label&lt;/label&gt;
  </code></pre>
  
  <p><strong>What I've got :</strong></p>
  
  <pre><code>&lt;label id="intLabel" data-int-array="System.Int32[]"&gt;My label&lt;/label&gt;
  </code></pre>
  
  <p><strong>What I would like to have :</strong></p>
  
  <pre><code>&lt;label id="intLabel" data-int-array='["1", "2", "3", "4"]'&gt;My label&lt;/label&gt;
  </code></pre>
  
  <p>Thanks !</p>