When I have a Model or ViewModel with values that are sent from the controller to the View but rendered in such a way that they are not submitted back to the controller when a form is posted, (e.g. a label whose contents is loaded from a data source) what is the preferred way to make those values available to the controller action that handles the POST request?
- Should I include hidden fields for everything I want to get back?
- Reload the data I need from the data source? (Yikes!)
- Use session variables?
- Is there another trick that I am unaware of?
I’d suggest re-loading it from the data source – that way you can also perform concurrency checks etc. I guess it depends what kind of scenario you are looking at – what sort of a user load are you expecting?
Based on your new comment above, given the small rate of requests, I’d absolutely go with reloading the data, makes things a lot simpler.