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.
Here's what I'm trying to do :
Controller :
public class HomeController : Controller
{
public IActionResult Index(){
int[] t = {1, 2, 3, 4};
ViewBag.t = t;
return View();
}
}
Razor View :
@{
ViewData["Title"] = "Home Page";
}
<label id="intLabel" data-int-array="@(ViewBag.t)">My label</label>
What I've got :
<label id="intLabel" data-int-array="System.Int32[]">My label</label>
What I would like to have :
<label id="intLabel" data-int-array='["1", "2", "3", "4"]'>My label</label>
Thanks !