viewbag和视图状态之间的区别? [英] Difference between viewbag and viewstate?

查看:217
本文介绍了viewbag和视图状态之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在MVC WebForms和ViewBag的ViewState之间的功能区别?他们似乎是同样的事情。而且可以以相同的方式使用。我问,因为MVC促进了无状态的Web,并在页面馅数据造成膨胀和性能下降。但似乎,你可以做,在MVC为好。他们所做的一切,貌似,只是给它一个新的名字。

Is there a functional difference between ViewState in Webforms and ViewBag in MVC? They seem to be the "same thing". And can be used in the same ways. I ask because MVC promotes the stateless Web and not stuffing data in the page causing bloat and slower performance. But it seems that you can do that in MVC as well. All they did, seemingly, is just give it a new name.

推荐答案

的ViewState 在Web窗体中的表单数据序列化为形式的隐藏,加密的领域,使数据可以重新绑定上回发。

ViewState in Web Forms was serializing form data into a hidden, encrypted field in the form, so data could be re-bound on the postback.

ViewBag / ViewData的是一本字典,你可以在东西数据导入。例如,您可以添加到它在你的控制器,然后访问它在你的视图。中的数据是动态这使得它难以处理数据。 ViewBag不会发送到客户端,它的MVC(服务器管道)的一部分。

ViewBag/ViewData is a dictionary where you can "stuff" data into. For example, you might add to it in your Controller, then access it in your View. The data is dynamic which makes it difficult to work with the data. ViewBag doesn't get sent to the client, it's part of the MVC (server pipeline).

两者,应该避免。

通过,那么,不使用它,并找到解决方法的ViewState。和ViewBag应使用的ViewModels的被避免。

ViewState by, well, not using it and finding workarounds. And ViewBag should be avoided by the use of ViewModels.

这篇关于viewbag和视图状态之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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