Hello,
i want to keep a List in the controller. and manipulate it via action the being invoked from a view page. currently i'm losing the data of the List on each request. what is the correct way to do that in ASP.NET MVC
Thanks
Hello,
i want to keep a List in the controller. and manipulate it via action the being invoked from a view page. currently i'm losing the data of the List on each request. what is the correct way to do that in ASP.NET MVC
Thanks
Since the controller is re-instantiated on each request, you can't.
Instead, use a database of some kind - there are really fast ones out there, if performance is the reason you wanted a list in the first place. Try SQLite, for example. I haven't done any real work with it myself, but from what I've heard it's really high-performing both for in-memory databases and file based.
An option could be some sort of singleton pattern, that instantiates the list on application start and then keeps it static for as long as the application runs. Not sure exactly how you'd do that though.
You can post that data in hidden fields and have it modelbind back (like in this example) or manage it in Session.