什么时候"可接受QUOT;使用ViewBag /的ViewData在ASP.NET MVC? [英] When is it "acceptable" to use ViewBag/ViewData in ASP.NET MVC?

查看:151
本文介绍了什么时候"可接受QUOT;使用ViewBag /的ViewData在ASP.NET MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到,最好的做法是使用强类型的意见,并通过在一个视图模型所有需要的数据,但我很好奇,如果有它实际上被认为是最佳实践的ViewBag /的ViewData来传递数据的情况下

I realize that the best practice is to use strongly typed Views and pass in all needed data in a ViewModel, but I am curious if there are situations where it is actually considered "best practice" to pass data in the ViewBag/ViewData.

在为ViewBag / ViewData的preferred什么情况下将数据传递到一个看法?

In what scenarios is the ViewBag/ViewData preferred for passing data to a view?

更新

这是伟大的听到各种用途每个人都拿出ViewBag / ViewData的。我们可能永远不会在一个最佳实践到达,但它会很高兴地看到不同的解决方案,人们纷纷拿出依赖于ViewBag / ViewData的。

It's great to hear the various uses everyone has come up with for ViewBag/ViewData. We may never arrive at a "best practice" but it will be great to see the different solutions people have come up with that rely on the ViewBag/ViewData.

推荐答案

我使用它们很少,对于一些完全无关的,我传递到视图中,再次模型或视图模型的信息位,大部分次我用一个视图模型

I use them rarely, for bits of information that are totally unrelated to the model or view model that I'm passing to the view, again, most of the times I use a view model

这篇关于什么时候"可接受QUOT;使用ViewBag /的ViewData在ASP.NET MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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