Reputation: 611
My title is probably terrible because I'm having trouble wording what I am trying to do.
I have an object that can potentially contain a huge number of records that looks something like this:
public class AssignmentGenerator : BaseGenerator
{
public bool IsLibrary { get; set; } = false;
public List<LineItem> LineItems { get; set; } = new List<LineItem>();
}
public class LineItem
{
public string Name { get; set; }
public string Value { get; set; }
}
I have a form created that allows editing of the values of the object, but it is possible for the list of line items to become very large (one example I have is ~ 3000). This being the case, I would like to make the line item list be a paged list in my view allowing editing of say 10 to 50 items at a time.
I've read a lot of tutorials and posts about how to do paging but none of the ones I've found go into how to do editing of a large set of data. I don't want to save the changes on each page to the database until the user actually clicks on the Save button. Is there a way to store the values in the object, retrieve them as needed, and then save upon user action?
Upvotes: 2
Views: 64
Reputation: 3302
The short answer is yes, there's a way - you're the programmer, you can do what you want. It's hard to give real code examples without more details, so below is just vague guidance.
You have to store their changes somewhere, but you can choose to save them in a staging database, or keep your AssignmentGenerator in memory on the server and just update the collection when they page (assuming 1 server or pinned sessions).
You will have to post the current state of the objects as the user changes pages (instead of just a Get endpoint). You don't have to save to the real database; you just update your temporary copy. The Save button should trigger a different controller action which moves your temporary copy to the real data store.
Upvotes: 2