0

We received a request from our client that they want every form on their site to store certain fields in a cookie, so that every time after the first submit, the form would be filled in with data from the cookie.

We created an actionfilter attribute to use on the methods that required this functionality. The idea would be to store the data of the FormCollection in the cookie, and every time the action gets called, we would check if the cookie exists and update the value accordingly.

The problem, is that the Form is read only, and cannot be modified. How would I achieve this functionality.

mateuscb
  • 10,150
  • 3
  • 52
  • 76

1 Answers1

1

One technique would be to create a custom model binder which populates the model from the cookie for the appropriate properties, and then uses the default model binder for the remaining properties.

You could derive from DefaultModelBinder as described here and here.

Community
  • 1
  • 1
devdigital
  • 34,151
  • 9
  • 98
  • 120
  • Interesting, I looked at that, but was afraid it was a bit more complex than necessary. But given your answer and examples this may be a viable solution. Will analyze this a bit further. – mateuscb Sep 18 '12 at 22:09