0
我想在MVC視圖中顯示ActiveDirectory用戶的thumbnailPhoto屬性。 我解析所需要的屬性一類名爲Employee的List:從字節設置img src屬性[]
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>
但是當我呼叫索引頁時,圖片將不會顯示。是否有其他可能性顯示個人資料照片?