Reputation: 2521
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?
Upvotes: 0
Views: 150
Reputation: 33857
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.
Upvotes: 6
Reputation: 10307
Without knowing completely the context of what you are doing I can't say for sure, but if you have, say, an edit form which would update an entity and maybe do some logic based on some data in the database, I'd reload your the data you need rather than store it client side and trust what has been sent back in the post is consistent with what you expect the data to be in your data store.
Upvotes: 3