MVC3 多步骤形式 - 如何持久化模型对象 [英] MVC3 multi step form - How to persist model object

查看:26
本文介绍了MVC3 多步骤形式 - 如何持久化模型对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用一个模型对象的多步骤表单,我需要在步骤之间保留它.只有在最后一步之后,对象才会被保存到数据库中.我看到有人建议使用 HTML.Serialize 但这个选项有多安全?

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?

此外,我的模型对象会随着用户填写表单而增长,这意味着带有序列化数据的隐藏表单字段将增加我的 HTML 输出的大小.

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?

推荐答案

我使用了 TempData 用于此目的.

I've use the TempData for this purpose.

您可以在 TempData 中存储一个对象(模型数据的副本),并在下一个请求中使用它.如果它在下一个请求中没有被阻止,它将被销毁".所以您不必担心它会填满您的会话.

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.

这篇关于MVC3 多步骤形式 - 如何持久化模型对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆