Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 将多个数组传递给视图_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 将多个数组传递给视图

Asp.net mvc 3 将多个数组传递给视图,asp.net-mvc-3,Asp.net Mvc 3,我创建了一个多数组myArr模型[10,10]。 然后,我希望该模型返回到我的视图中,并且我希望能够检查数组中的值 我的代码: 模型 看法 @model GraAjaxTeamProject.Models.MapModel @{ ViewBag.Title=“主页”; } @对于(int i=0;i

我创建了一个多数组myArr模型[10,10]。 然后,我希望该模型返回到我的视图中,并且我希望能够检查数组中的值

我的代码: 模型

看法

@model GraAjaxTeamProject.Models.MapModel
@{
ViewBag.Title=“主页”;
}
@对于(int i=0;i<10;i++)
{
@对于(int j=0;j<10;j++)
{
if(Model.MapTilesArray[i,j]==1)
{
}  
}
}

运行此操作时,出现错误,传递到字典中的模型项的类型为“System.Int32[,]”,但此字典需要类型为“GraAjaxTeamProject.Models.MapModel”的模型项。

您正在将MapModel传递到视图中。将@model更改为
int[,]
或从您的查看调用中删除
.MapTilesArray

根据视图中给出的示例,您应该更改行

public ActionResult Index()
{
    var map = mapModel.MapTilesArray;

    return View(map);
}

   public MapModel mapModel = new MapModel();

    public ActionResult Index()
    {
        var map = mapModel.MapTilesArray;

        return View(map);
    }
  @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>
 }
public ActionResult Index()
{
    var map = mapModel.MapTilesArray;

    return View(map);
}
public ActionResult Index()
{
    return View(mapModel);
}