c# - Variable ViewBag name in MVC -


basically, i'm working on project , i'm not sure how can put variable viewbag name, want because following code inside of while loop.

list<selectlistitem> permissionlevels = new list<selectlistitem>(); permissionlevels.add (new selectlistitem  {//skipping section, not relevant viewbag.@contactname = permissionlevels; 

and in view have inside of foreach loop:

@html.dropdownlist(_currentpermissions.name) 

(yes, _currentpermissions correct name located.)

what i'm trying here @contactname variable i'm not sure how it, best guess , can't seem find way it

you can't this. fear not! there's better way handle problem.

if need list of objects returned view, store list in viewbag or store property on model.

since sounds you're building list of permissions per user, might something this:

var permissionsdictionary = new dictionary<string, list<selectlistitem>>();  foreach (var user in users) {     var listitems = new list<selectlistitem>();      listitems.add(new selectlistitem() {         //do stuff!     });      permissionsdictionary.add(user.name, listitems); }  model.permissions = permissionsdictionary; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -