MVC ViewData和ViewBag
Controller
public ActionResult Index(){List<string> colors = new List<string>();colors.Add("red");colors.Add("green");colors.Add("blue"); ViewData["listColors"] = colors;ViewData["dateNow"] = DateTime.Now;ViewData["name"] = "Hajan";ViewData["age"] = 25;return View();} |
Controller
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public ActionResult Index(){List<string> colors = new List<string>();colors.Add("red");colors.Add("green");colors.Add("blue");ViewBag.ListColors = colors; //colors is ListViewBag.DateNow = DateTime.Now;ViewBag.Name = "Hajan";ViewBag.Age = 25;return View(); } |
你和上面的对比 你看见了不同吗?
1.使用ViewData
2.使用ViewBag


MVC ViewData和ViewBag的更多相关文章
- asp.net mvc ViewData 和 ViewBag区别,TempData
ViewData 和 ViewBag都是页面级别的生命周期,TempData--Passing data between the current and next HTTP requests Temp ...
- ASP.net MVC+ViewData VS ViewBag
在使用MVC框架的过程中,往界面传值,我们使用的ViewData.如ITOO部分代码图解: 当然除了ViewData,我们还能够使用同卵兄弟(ViewBag)来完毕相同的功能,详情 ...
- MVC ViewData和ViewBag[转]
转自:http://blog.csdn.net/a497785609/article/details/7854402#t0 视图数据可以通过ViewBag属性访问,它主要是为了从Contr ...
- MVC ViewData与ViewBag的区别
一.ViewData 1.ViewData派生自ViewDataDictionary,所以它具有字典的属性,例如:ContainsKey .Add .Remove 和 Clear : 2.字典键值是字 ...
- MVC ViewData和ViewBag 参数名一样表示同一个值
@ViewData["MenuName"] 和 @ViewBag.MenuName 表示同一个值
- 在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下:
Asp.net MVC中的ViewData与ViewBag ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从Asp.net MVC 1 就有了 ASP. ...
- Asp.net MVC的ViewData与ViewBag以及TemplateData的使用与区别
ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从Asp.net MVC 1 就有了 ASP.NET MVC3 才有 基于Asp.net 3.5 fram ...
- asp.net mvc中ViewData、ViewBag和TempData的详解
一.ViewData和ViewBag 1.ViewData和ViewBag都是从Action向View传递数据的方式,当然还有其他方式如向View传递Model. 2.ViewData页面查询数据时需 ...
- .NET MVC TempData、ViewData、ViewBag
说明: 原文作者贤新 原文地址:http://www.cnblogs.com/chenxinblogs/p/4852813.html ViewData和ViewBag主要用于将数据从控制器中传递到视图 ...
随机推荐
- RH的NFS配置--简单OK
参照文档: http://wenku.baidu.com/link?url=SAcDvj8WtBd8dunC7P6FTFADYYVzzxhOiNJqbgr-aGTZovM0lHg-wbYgv9I3Lu ...
- 要将PYTHON应用于工作啦
分析同事在线答疑的数据,考评模型还未最终给出: import time import sys import optparse #操作代码和同事名对应的文件 opfile = 'op_name.txt' ...
- 纯CSS打造可折叠树状菜单
1:Html代码 <li> <label for="subsubfolder1">下级</label> <input id="s ...
- AlarmManager.setRepeating将不再准确
背景: 当我们想让Android应用程序定时为做一件工作时,我们往往会在一个BroadcastReceiver中使用AlarmManager.setRepeating()方法来实现.在API 19(即 ...
- mysql表分区、查看分区
原文地址:http://blog.csdn.net/feihong247/article/details/7885199 一. mysql分区简介 数据库分区 数据库分区是一种物理数据库设 ...
- Hadoop 新 MapReduce 框架 Yarn 详解
Hadoop 新 MapReduce 框架 Yarn 详解: http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/ Ap ...
- lambda -- Filter Java Stream to 1 and only 1 element
up vote10down votefavorite I am trying to use Java 8 Streams to find elements in a LinkedList. I wan ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- MySQL5.5 所支持的存储引擎
本博文的主要内容有 .存储引擎的概念 .MySQL5.5 所支持的存储引擎 .操作默认存储引擎 .选择存储引擎 与其他的数据库软件不同,MySQL数据库软件提供了一个名为存储引擎的概念,由于存储引擎是 ...
- 【转】Gabor 入门
Computer Vision Tutorials Search Primary Menu Skip to content Tutorials Search for: Gabor Filters ...