arrays - Set img src property from byte[] -


i'm trying show thumbnailphoto property of activedirectory user on mvc view. i'm parsing needed properties list of class named employee:

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,                     });                 }             } 

i did research on how display picture on index view , found possible solution:

<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> 

but when call index page, pictures won't shown. there other possibility show profile pictures?

finally found solution. had remove braces around @imgsrc in

  <img src="{@imgsrc}" title="@html.displayfor(i => item.lastname), @html.displayfor(i => item.firstname)" /> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -