使用ViewBag在MVC不好? [英] Is using ViewBag in MVC bad?

查看:152
本文介绍了使用ViewBag在MVC不好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它看起来像MVC 3团队决定在控制器和视图之间的动态数据交换功能,使称为viewbag但它是针对强类型的视图我们都知道一件好事吗?想你的意见。就是这个功能将取代强类型的看法? (的ViewModels)

It seem like mvc 3 team decided to bring in a feature for dynamic data exchange between a controller and a view called the viewbag but it is A good thing against the strongly typed view we all know about? Would like your opinion .. Is this feature going to replace strongly typed view ? (viewmodels)

推荐答案

该ViewBag是previous ASP.NET MVC 1和2同样的事情,它的ViewData恰好是动态的,而不是需要使用它像钥匙的字典。我不认为这将取代所有强类型的意见,实际上你应该使用可视数据/ Viewbag尽可能少。始终使用强类型的意见尽可能因为这将导致更少的错误,如果在你的可视数据/ Viewbag更改名称并没有蒙上ViewData的所有的地方做HTML清洁。

The ViewBag is the same thing as ViewData in previous ASP.NET MVC 1 and 2. It just happens to be dynamic instead of needing to use it like a dictionary with keys. I don't think this will replace strongly typed views at all and in fact you should use Viewdata/Viewbag as little as possible. Always use strongly typed views whenever possible since it will lead to fewer errors if the names in your Viewdata/Viewbag change and make the HTML cleaner by not having ViewData casts all over the place.

这篇关于使用ViewBag在MVC不好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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