I'm trying to figure out the best approach for a specific task. In my index method, I am either searching, filtering, or retrieving data from my database. I then send n items to the view. If there are more than n items, I need to implement paging. One option is to query the database again to retrieve the next set of n elements, or I could persist all the filtered or search results and just fetch the next n elements from that stored data. It seems that using sessions is not advisable, so instead of an IEnumerable of this class:
public class CatalogModel
{
public string Price;
public string deviceName;
public string imgUrl;
}
I have chosen 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 want to store all my data in the field:
public IEnumerable<Device> Devices
and send it to the controller each time. However, I am unsure how to access it from JavaScript in order to post it back with ajax.
Is this a feasible approach, and would it be more efficient than querying the database each time?
Thank you!