So I am trying to pass the data (int-Array) from my Model...
namespace MvcApplication2.Models {
public class Sudoku {
public int[] numbers { get; set; }
}
}
..., initialized with indices by the Controller ...
namespace MvcApplication2.Controllers
{
public class SudokuController : Controller
{
//
// GET: /Sudoku/
[HttpGet]
public ActionResult Index()
{
Sudoku sudoku = new Sudoku();
int[] numbers = new int[81];
for (var i = 0; i < 81; i++) {
numbers[i] = i;
}
sudoku.numbers = numbers;
return View(sudoku);
}
}
}
... through the View ...
@model MvcApplication2.Models.Sudoku
@{
ViewBag.Title = "Sudoku";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Sudoku</h1>
<div class="sudoku"></div>
@section scripts {
<script id="script1" src="~/Scripts/render_sudoku.js" type="text/javascript" data-numbers=@Model.numbers></script>
}
... into my JavaScript file, where I just want to use it as an array.
However, when I try
console.log($('#script1').data("numbers"));
,
I only get
System.Int32[]
as an answer, which seems to be a String only describing the format.
Is it possible to work with the actual Array in the JavaScript file?
I'm new to MVC and can't quite get the grasp of it.