0
나는 이미지 필드가있는 사용자 정보가 들어 있고 이진 데이터에 이미지를 저장하는 테이블을 가지고 있습니다.Asp.net-mvc3의 데이터베이스에서 테이블의 이미지를 표시하십시오.
사용자 정보가있는 테이블의 내보기 페이지에이 이미지를 표시하고 싶습니다.
내 코드는 ... 컨트롤러
public ActionResult About()
{
var data = db.dbtable.ToList();
return View(data);
}
가져 오기 이미지 방법 // 등록은 ..
@model IEnumerable<MvcMySchool.dbtable>
<table width="50">
<tr>
<th>
Registration No.
</th>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>
City
</th>
<th>
Photo
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.RegNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@*HttpContext.Current.Response.Write("<img width="75" height="75" [email protected](Url.Action("GetImage", "Home", new { id = item.RegNo })) />")*@
<img width="75" height="75" [email protected](Url.Action("GetImage", "Home", new { id = item.RegNo })) />
</td>
</tr>
}
</table>
그것은 단지 쇼 DBTABLE
보기 페이지public FileContentResult GetImage(int id)
{
reg = db.dbtable.FirstOrDefault(i => i.RegNo == id);
if (reg != null)
{
return File(reg.Photo, "image/jpeg");
}
else
{
return null;
}
}
의 목적은 첫 번째 행의 이미지와 그 이후의 이미지는 없습니다.
감사합니다 ...
감사에 대한
내가 제 1 논리가에 하나 개의 이미지를 표시 테이블의 첫 번째 행. 나는 데이터베이스의 모든 이미지를 원하고 각 테이블 행의 각 이미지를 보여줍니다. – krish
Ok. '@foreach (모델의 var 항목) {} –
출력이 변경되지 않았습니다. 또한 경로가 후 렌더링의 '@foreach (모델의 var 항목) {}'페이지에서 사용되는 경우 – krish