asp.net mvc - Create Index with single drop down list -


i want create index page starts single drop down list. once user selects category, , second drop down list appear (via ajax call) allow user select model item edit. using code in controller , view below, however, getting following error

the model item passed dictionary of type 'system.collections.generic.list'1[monet.models.dropdownvalues]', dictionary requires model item of type 'monet.models.dropdownvalues'.

controller

    public actionresult index()     {         //redirect if security not met.          if (!security.isadmin(user)) return redirecttoaction("message", "home", new { id = 1 });          var dropdownvalues =  (from b in db.dropdownvalues                               orderby b.model                               select b.model).distinct();          viewbag.categoryoptions = new selectlist(dropdownvalues, "model", "model");          return view(db.dropdownvalues.tolist());     } 

view

@model monet.models.dropdownvalues  @{     viewbag.title = "monet administration"; }  <h2>monet administration</h2> update values drop down boxes  <div>     <span style="float: left;">         <div class="editor-label">         @html.labelfor(model => model.model)         </div>         <div class="editor-field">         @html.dropdownlist("categories", (selectlist)viewbag.categoryoptions, "")         @html.validationmessagefor(model => model.model)         </div>     </span>     <div style="clear: both;"></div> </div> 

your view expects single instance of monet.models.dropdownvalues , you're passing list<monet.models.dropdownvalues>

you should either pass single item controller (if makes sense):

return view(db.dropdownvalues.tolist().first()); 

or change model type in view:

@model list<monet.models.dropdownvalues> 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -