c# - How to bind a dictionary value to a column in asp.net mvc -
i using active directory authentication library list of users in active directory. view bound user class in library.
@using microsoft.azure.activedirectory.graphclient @model ienumerable<user> @{ viewbag.title = "index"; layout = "~/areas/globaladmin/views/shared/_layoutglobaladmin.cshtml"; } <h2>usuarios</h2> <div class="wrapper wrapper-content animated fadeinright"> <div class="row"> <div class="col-lg-12"> <div class="ibox float-e-margins"> <div class="ibox-title"> <h5>lista de usuarios</h5> <div class="ibox-tools"> @html.actionlink("create new", "create", null, new { @class = "btn btn-primary btn-xs" }) </div> </div> <div class="ibox-content"> <table id="directoryobjects" class="table table-bordered table-striped"> <tr> <th> userprincipalname </th> <th> displayname </th> <th> jobtitle </th> <th> objectid </th> <th /> </tr> @foreach (var item in model) { var user = item user; <tr> <td> @html.displayfor(modelitem => user.userprincipalname) </td> <td> @html.displayfor(modelitem => user.displayname) </td> <td> @html.displayfor(modelitem => user.jobtitle) </td> <td> @html.displayfor(modelitem => user.objectid) </td> <td> @html.actionlink("edit", "edit", new { objectid = item.objectid }) <br /> @html.actionlink("details", "details", new { objectid = item.objectid }) <br /> @html.actionlink("delete", "delete", new { objectid = item.objectid }) <br /> @html.actionlink("groupmembership", "getgroups", new { objectid = item.objectid }) <br /> @html.actionlink("directreports", "getdirectreports", new { objectid = item.objectid }) <br /> </td> </tr> } </table> </div> </div> </div> </div> </div>
however in active directory can create custom properties, properties called schema extensions: fyi http://justazure.com/azure-active-directory-part-6-schema-extensions/
in list of users users have custom properties others dont.
in view want create column show value of custom property if exists.
i know how value server side, dont know how bind on html
this index action in users controller
public async task<actionresult> index() { var userlist = new list<microsoft.azure.activedirectory.graphclient.user>(); try { activedirectoryclient client = authenticationhelper.getactivedirectoryclient(); ipagedcollection<iuser> pagedcollection = await client.users.executeasync(); if (pagedcollection != null) { { list<iuser> userslist = pagedcollection.currentpage.tolist(); foreach (iuser user in userslist) { var usuarioad = (microsoft.azure.activedirectory.graphclient.user)user; var extendedproperties = usuarioad.getextendedproperties(); foreach (var property in extendedproperties) { if (property.key.contains("compania")) { string value = property.value.tostring(); } } userlist.add((microsoft.azure.activedirectory.graphclient.user)user); } pagedcollection = await pagedcollection.getnextpageasync(); } while (pagedcollection != null); } } catch (exception e) { if (request.querystring["reauth"] == "true") { // // send openid connect sign-in request new set of tokens. // if user still has valid session azure ad, not prompted credentials. // openid connect middleware return controller after sign-in response has been handled. // httpcontext.getowincontext() .authentication.challenge(openidconnectauthenticationdefaults.authenticationtype); } // // user needs re-authorize. show them message effect. // viewbag.errormessage = "authorizationrequired"; return view(userlist); } return view(userlist); }
how can bind value? or maybe can write complex expression on razor view without writing on controller value?
i thought question , name sounded familiar, , that's when realised gave answer your question earlier. , think question here linked other question had.
i don't quite index
controller does, not important in answering question.
i not use dictionary property extended properties. rather use collection of objects of, extendedproperty
class, consists of 2 properties: name
, value
.
so user
class have this:
public ilist<extendedproperty> extendedproperties
in view, you'd this... note replace foreach
loop for
loop.
@for(int = 0; < model.count(); a++) { var user = model[a]; ... @if (user.extendedproperties != null && user.extendedproperties.count() > 0) { (int = 0; < user.extendedproperties.count(); i++) { @html.displayfor(m => m[a].extendedproperties[i].name) @html.displayfor(m => m[a].extendedproperties[i].value) } } }
Comments
Post a Comment