I’m storing ViewModel in session.
There is a problem with live environment. Because of configuration, I can’t store non serializable classes in session and SelectList not marked as Serializable.
What is the better way to exclude usage of SelectList in ViewModel as a DataSource for DropDown controls?
You could store in your view model the collection of items, not the select list.
Then, add a method to your ViewModel called
GetSelectList()that creates a SelectList using the collection.That way, you store the data, and once you retrieve that object from session, you can call the
GetSelectList()method to use it in the dropdownlist.You could even pass a parameter to set the selected value.