ViewBag与ViewData有什么区别? [英] What is the difference between ViewBag to ViewData ?

查看:85
本文介绍了ViewBag与ViewData有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ViewBag.LogoFileId = new SelectList(db.Files, "FileId", "FileId", chain.LogoFileId);
ViewBag.LangId = langId;
ViewData["catid"] = catid;
ViewData["languages"] = db.Languages.OrderBy(l => l.LanguageId).ToList();

推荐答案

ViewData就像一个你添加东西的集合,而ViewBag是一个动态类型,所以你只需设置和读取它的属性。 ViewData是在实现动态类型之前构思的,因此它是一种保存可在运行时定义的对象集合的方式。
ViewData acts like a collection you add things to, whereas ViewBag is a dynamic type so you simply set and read properties on it. ViewData was conceived before dynamic types were implemented so it was a way of holding a collection of objects you could define at run-time.


你好,

之一你可以参考的最好的文章和更好的理解:

ViewBag与ViewData对比TempData与会话 [ ^ ]



希望这可以清除你的概念这里。

谢谢
Hello,
One of the best articles you can refer for this and better understanding:
ViewBag Vs ViewData Vs TempData Vs Session[^]

Hope this clears your concept here.
Thanks


这篇关于ViewBag与ViewData有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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