我试图在MVC视图上显示ActiveDirectory用户的thumbnailPhoto属性。 我将所需的属性解析为名为Employee的类的List:
for (int counter = 0; counter < resultCol.Count; counter++)
{
result = resultCol[counter];
if (result.Properties.Contains("samaccountname") &&
result.Properties.Contains("displayname") &&
result.Properties.Contains("sn") &&
result.Properties.Contains("givenName"))
{
list.Add(new Employee
{
Email = (String)result.Properties["samaccountname"][0],
FirstName = (String)result.Properties["givenName"][0],
LastName = (String)result.Properties["sn"][0],
pictureBLOB = result.Properties.Contains("thumbnailPhoto") ? (byte[])result.Properties["thumbnailPhoto"][0] : null,
});
}
}
我做了一些关于如何在索引视图上显示图片的研究,并发现这是一个可能的解决方案:
<div class="container">
@foreach (var item in Model)
{
String imgSrc = String.Empty;
String base64 = String.Empty;
if (item.pictureBLOB != null)
{
base64 = Convert.ToBase64String(item.pictureBLOB);
imgSrc = String.Format("data:image;base64,{0}", base64);
}
<div id="@Html.DisplayFor(i => item.Number)" class="col col-lg-2 col-md-4 col-sm-6">
<a class="post" mailto="@item.Email" href="#">
<img src="{@imgSrc}" title="@Html.DisplayFor(i => item.LastName), @Html.DisplayFor(i => item.FirstName)" />
@*onerror="this.src = '../../Content/Images/nopicture.gif';" />*@
</a>
</div>
}
</div>
但是当我调用索引页面时,图片不会显示。是否有其他可能显示个人资料图片?
答案 0 :(得分:0)
最后我找到了解决方案。我只需要删除
中@imgSrc周围的大括号 <img src="{@imgSrc}" title="@Html.DisplayFor(i => item.LastName), @Html.DisplayFor(i => item.FirstName)" />