ViewBag里面有什么? [英] What is inside ViewBag?

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

问题描述

ASP.net/mvc教程中,有 ViewBag.Message ViewBag.NumTimes 等.这些属性的数据类型是什么?他们在解决方案中的什么位置声明了?

In the MSDN documentation, there are ViewBag.MyMessageToUsers and ViewBag.AnswerText. In the ASP.net/mvc tutorial, there are ViewBag.Message, ViewBag.NumTimes and such. What are the data types of these properties? And where in the solution are they declared?

推荐答案

ViewBag是动态集合.在您的控制器中,您可以将所需的任何内容放入其中,然后从视图中调用它.它们可以是您想要的任何对象和任何类型.

ViewBag is a dynamic collection. In your controller you can put whatever you want in it and call it from your View. They can be whatever objects and whatever types you want.

您提供的指向

The link you provided to the MSDN Documentation is providing an example of this.

如果您的控制器中包含以下内容:

If you have the following in your controller:

ViewBag.Something = thing;

事物在某处声明,您正在这里访问它.您无需声明 ViewBag ,并且在为其分配 thing 时, Something 会自动声明.

thing is declared somewhere, and you are accessing it here. You don't declare ViewBag, and Something gets automatically declared when you assign thing to it.

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

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