MVC3 multi step form - How to persist model object

时间秒杀一切 提交于 2019-11-27 15:16:37

问题


I have a multi step form which uses one model object and I need to persist it between the steps. The object gets saved to the database only after the final step. I have seen people suggest using HTML.Serialize but how secure is this option?

Also my model object will grow as the user fills up the form which means the hidden form field with serialized data will add up size to my HTML output.

Whats the best practice for this kind of situation?


回答1:


I've use the TempData for this purpose.

You can store an object (a copy of your model data) in TempData, and use it in the next request. If it is not set-back in the next request it will be "destroyed". So you do not have to worry that it is filling up your session.




回答2:


Think about your Controller as a state machine where every action is a step in the wizard. About the persistence between steps is not big deal anyway is a simple POCO as a Dto, Command which is gonna to be send to your domain interface for validation and processing. You can store it in your IoC, Session, Cache, FileSystem ... I hope you got it. Keep it simple and clean.



来源:https://stackoverflow.com/questions/5181695/mvc3-multi-step-form-how-to-persist-model-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!