I wondering what is the best way to accomplish this task: In my index method I'm either searching or filtering or just taking data from my db. Then I send n items to view. If there more than n items I need some paging to be done. As I understand I can query my db again filter or search and take next n elements or I can somehow persist all my data(filtered or data received after search query) and just take n next elements from it. As I understand session is not the best way to accomplish it, so instead of IEnumerable of this class
public class CatalogModel
{
public string Price;
public string deviceName;
public string imgUrl;
}
I've decided to use this class
public class CatalogView
{
public IEnumerable<CatalogModel> Catalog;
public IEnumerable<Device> Devices;
public CatalogView(IEnumerable<CatalogModel> catalog = null, IEnumerable<Device> devices = null)
{
Catalog = catalog;
Devices = devices;
}
}
I wand to keep all my data in
public IEnumerable<Device> Devices
this field and each time send it to controller, but I don't know how can I access it from javascript so I can post it back with ajax.
Is it possible to do it such way and will it be more efficient than querying each time my db.
Thank you!