I'm just starting with ASP.Net MVC 2 and might be doing something wrong. I have a controller who builds some objects and passes them to a view using ViewData. In the view I display the data etc ... and then want to submit the same data (plus other user input) back to the same controller. Is there any simple way to do this ?
I'll provide a more detailed description of the problem if necessary.
Thanks and good day :)
EDIT : I read more on ViewModels fearing that I wasn't using them properly but apparently they're not a solution. My problem isn't getting data to the view (I already use a view model for that), but returning the data back to the controller. I use complex objects, so even sending a form with hidden fields wouldn't really be a good solution as it will require me to serialize my objects, which is too much hassle for a task that should be simple. I'm going to have a look at sessions for now.
EDIT 2: Ok, I solved the problem using sessions, couldn't be easier :)
Consider any of these solutions to keep state between requests:
Html.Hidden("foo", myData);
If you choose to write to hidden inputs, consider faking ViewState. It's a non-optimal solution though.
I'd prefer Session overall. There's no tampering, and you can hold complex objects. Obviously the drawbacks to Session are future scaling performance, timeouts, and concurrency with multiple sessions. Some of those problems can easily be mitigated, though.