在MVC 5中保留视图之间的数据 [英] Persist data between views in MVC 5

查看:63
本文介绍了在MVC 5中保留视图之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在Microsoft MVC 5项目上工作,似乎遇到了障碍。我有两个不同形式的部分视图
,并且当我从一个局部视图切换到另一个局部视图然后再返回到第一个局部视图时,我希望将数据保留在字段中。我想我可以通过创建一个"父"来做到这一点。我将每个表单的模型作为属性的模型。使用html.beginform可以很好地使用
,但是我希望它能够使用ajax表单,这样我就不必重定向了。我将如何做这样的事情?

解决方案

您应该在asp.net mvc特定论坛上发帖,以获得更好的支持。



如果我理解你的目标是什么,你可以考虑使用TempDataDictionary。它基本上将数据存储在会话中。


https://msdn.microsoft.com/en-gb/library/system.web.mvc.tempdatadictionary(v = vs.100).aspx


https:// msdn.microsoft.com/en-gb/library/dd394711%28v=vs.100%29.aspx?f=255&MSPPError=-2147217396



I'm working on a Microsoft MVC 5 project and seem to have hit a roadblock. I have two partial views with different forms and want to keep the data in the fields when I switch from one partial view to another and then back to the first one. I figured I could do this by creating a "parent" model in which I have the models for each form as a property. This works great with html.beginform but I want to make it work with an ajax form so that I don't have to redirect. How would I go about doing something like this?

解决方案

You should be posting in the asp.net mvc specific forum, for better support.

.

If I understand correctly what you're aiming to do, you could consider TempDataDictionary. It stores data in session, basically.

https://msdn.microsoft.com/en-gb/library/system.web.mvc.tempdatadictionary(v=vs.100).aspx

https://msdn.microsoft.com/en-gb/library/dd394711%28v=vs.100%29.aspx?f=255&MSPPError=-2147217396


这篇关于在MVC 5中保留视图之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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