我正在使用asp.net mvc开发一个Web应用程序。我有一组扬声器,我想在其中显示相应的扬声器名称。我已经使用数组来检索数据。但是它没有使用其他参数。我的观点是:
@model List<CTCFremont.View_Details>
@{
ViewBag.Title = "Leaders";
}
<style>
.img-circle {
border-radius: 50%;
}
</style>
<h2>Leaders</h2>
<div class ="container">
<table>
@{
int j = 0;
for (int i = 0; i < Model.Count(); i+= 1)
{
j = i;
<tr>
@while (j <= i && j < Model.Count())
{
<td>
<img src="data:image/png;base64,@Convert.ToBase64String(Model[j].Picture,0,Model[j].Picture.Length)" width="250" height="250" class="img-circle" />
</td>
j++;
}
</tr>
<tr>
@while (j <= i && j < Model.Count())
{
<td>
<b>@Html.DisplayFor(modelItem => Model[j].Name)</b>
</td>
j++;
}
</tr>
<tr>
@while (j <= i && j < Model.Count())
{
<td>
<b>@Html.DisplayFor(modelItem => Model[j].Position)</b>
</td>
j++;
}
</tr>
//foreach (var item in Model) {
// }
}
}
</table>
</div>
我的模特是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CTCFremont.Controllers
{
public class View_DetailsController : Controller
{
//
// GET: /View_Details/
public ActionResult Gallery()
{
List<View_Details> all = new List<View_Details>();
// Here MyDatabaseEntities is our datacontext
using (CTCFremontEntities dc = new CTCFremontEntities())
{
all = dc.View_Details.ToList();
}
return View(all.ToList());
}
public ActionResult Index()
{
return View();
}
}
}
答案 0 :(得分:0)
我认为你已经多次使用模型循环复杂化了。这是你想要做的吗?
foreach (var item in Model)
{
<tr>
<td>
<img src="data:image/png;base64,@Convert.ToBase64String(item.Picture,0,item.Picture.Length)" width="250" height="250" class="img-circle" />
</td>
</tr>
<tr>
<td>
<b>@item.Name</b>
</td>
</tr>
<tr>
<td>
<b>@item.Position</b>
</td>
</tr>
}