c# - How to get the values from Html.ListBox in asp.net MVC -
i had before
<div class="form-group"> @html.label("empresa", new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.dropdownlist("empresa", new selectlist(empresas, "id", "nombre"), new { @class = "form-control" }) </div> </div>
and on controller values: (check request.form line)
public async task<actionresult> create( [bind( include = "userprincipalname,accountenabled,passwordprofile,mailnickname,displayname,givenname,surname,jobtitle,department" )] microsoft.azure.activedirectory.graphclient.user user) { activedirectoryclient client = null; try { client = authenticationhelper.getactivedirectoryclient(); } 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(); } try { var usuario = user.userprincipalname; user.userprincipalname = usuario+settingshelper.domain; user.mailnickname = usuario; user.accountenabled = true; await client.users.adduserasync(user); string extproplookupname = string.format("extension_{0}_{1}", settingshelper.clientid.replace("-", ""), "compania"); //to finished user.setextendedproperty(extproplookupname, request.form["empresa"].tostring()); await user.updateasync(); //task.waitall(); // save extended property value azure ad. user.getcontext().savechanges(); return redirecttoaction("index"); } catch (exception exception) { modelstate.addmodelerror("", exception.message); return view(); } }
however changed dropdownlist listbox because need multipleselect, , dont see in request.form collection
how can values selected?
use formcollection have here.
like so:
public actionresult myaction(formcollection formcollection) { var addeditems = formcollection["empresa"].split(','); //....more code stuff items }
Comments
Post a Comment