c# - How to pass multiple parameters to a view? -


i passing 2 list variables in actionresult below.

public actionresult index() {     list<category> cat = _business.viewallcat().tolist();     list<books> book = _business.viewallbooks().tolist();     return view(book); } 

when run code below error

the model item passed dictionary of type system.collections.generic.list1[durgesh_bhai.models.category], dictionary requires model item of type system.collections.generic.ienumerable1[durgesh_bhai.models.books].

when using 1 list in actionresult working fine.

i new mvc solution got create class hold required objects data members , pass object of class.

i created class called data , assigned objects object of class , sent object model.

or can use view bag

class data {   public list<category> cat {get;set;}    public list<books> book {get;set;}    public data()    {       this.cat = new list<category>();       this.book = new list<books>();    }  }  public actionresult index() {     data d=new data();      d.cat = _business.viewallcat().tolist();     d.book = _business.viewallbooks().tolist();     return view(d); } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -