I created my model to be a multiple array myArr[10,10]. Then I want that model to be returned to my view and I want to be able to check what values are in the array.
My code: model
public class MapModel
{
private int[,] mapTilesArray = new int[10, 10];
public int[,] MapTilesArray
{
get { return mapTilesArray; }
set
{
mapTilesArray = value;
}
}
public MapModel()
{
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
{
mapTilesArray[i, j] = 1;
};
}
controler
public MapModel mapModel = new MapModel();
public ActionResult Index()
{
var map = mapModel.MapTilesArray;
return View(map);
}
view
@model GraAjaxTeamProject.Models.MapModel
@{
ViewBag.Title = "Home Page";
}
@for (int i = 0; i < 10; i++)
{
<div>
@for (int j = 0; j < 10; j++)
{
if (Model.MapTilesArray[i,j] == 1)
{
<div style="height:30px;width:30px;border:1px solid gray;background-color:red;display:inline-block;"></div>
}
}
</div>
}
when I run this i have error The model item passed into the dictionary is of type 'System.Int32[,]', but this dictionary requires a model item of type 'GraAjaxTeamProject.Models.MapModel'.