c# - There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Clients' -


i have variable populating records database. display list on view drop down box. however, fails once reaches drop down.

controller:

  public actionresult review() {             var reviews = reviewrepo.getallreviews();              var clients = clientrepo.clients();                  list<selectlistitem> items = new selectlist(clients, "clientid", "clientname").tolist();             items.insert(0, (new selectlistitem { text = "default", value = "0" }));             viewbag.listofclients = items;              ienumerable<adminreviewviewmodel> model = reviews.select(s => new adminreviewviewmodel() {                 clientid = s.clientid,                 reviewid = s.reviewid,                 reviewname = s.reviewname,                 reviewperiodid = s.reviewperiodid,                 reviewperiodname = s.reviewperiod             });              return view(model);         } 

view:

@using (html.beginform("review", "useradmin", formmethod.post)) {     @html.dropdownlist("clients", viewbag.listofclients selectlist, new { @class = "grdropdown", @id = "reportdd"})     <button type="submit" value="submit" class="btn btn-default">submit</button> } 

fixed it. clue in error message. complaining there not client. because in drop down box expecting clientid , clientname. instead receives value , text. changed drop down this:

 @html.dropdownlist("clients", new selectlist(viewbag.listofclients, "value", "text"), new { @class = "grdropdown", @id = "reportdd" }) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -