0

For one of my projects I need to allow the user to select some products out of a table. This table will be paged (+2k records in DB).

So the user needs to be able to select items on different pages without losing them. I was thinking about using 2 tables. One table to select items from and another table(also with paging) where the selected items will be displayed.

But I have no idea how to persist the selected items without using Sessions... If anybody has a better idea please share it.

Edit: It is possible(won't happen that much) to select all products (+2k records). I don't know how mvc will behave if you have 2k hidden fields. Also lets say i use hidden fields and have the following in my viewmodel

public List<int> SelectedIds {get;set;}

I can then use hidden fields with "SelectedIds[i]" as name(replacing i by an integer). But the user can also deselect the items again. And I don't think the binding will work when you skip numbers. ex: 2 hidden field with these names "SelectedIds[0]" && "SelectedIds[2]"

This is something I'll have to test when i am home...

Beejee
  • 1,836
  • 2
  • 17
  • 31
  • Have you tried using hidden fields? – Suhas Sep 30 '13 at 08:28
  • check this link you will find what you are looking for. http://stackoverflow.com/questions/17967369/what-are-the-alternatives-of-session-variables – user123456 Sep 30 '13 at 08:33
  • Perhaps ViewState would be a viable alternative if you are concerned about the amount of data that could be used in session state? Admittedly this comes under the banner of 'hidden fields' but could be more manageable (i.e. you can make your property 'SelectedIds' wrap ViewState["SelectedIds"] which will contain a List). You will need to balance use of ViewState with the fact that a lot of data will be sent to the client each time. – SpruceMoose Sep 30 '13 at 11:52

0 Answers0