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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.