Asp.net mvc 3 将多个数组传递给视图
我创建了一个多数组myArr模型[10,10]。 然后,我希望该模型返回到我的视图中,并且我希望能够检查数组中的值 我的代码: 模型 看法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
@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);
}