Home  >  Article  >  Web Front-end  >  MVC页面常见三种传值方式??ViewData,ViewBag,TempData_html/css_WEB-ITnose

MVC页面常见三种传值方式??ViewData,ViewBag,TempData_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:53:351580browse


           最近接触MVC代码多了,发现了很多新东西,比如页面传值。发现了MVC里面原来有这么多对象可以用来传值,最近两天用到了ViewData和ViewBag,之后又关联到了TempData,现在列个表格比较下:



          





       用过之后,个人感觉还是ViewBag最好用,直接属性赋值就可以了,但是ViewData和TempData又有它们的优势,在使用的时候,可以根据要传递数据的大小,是从Controller向Views里面传递数据,还是Controller传递数据。。。综合考虑各种因素再做决定吧。




         除了这三种比较常见常用的,还有一种要提一下,就是model,用的时候也是访问属性就行了,另外,像UpdateModel,ViewModel。。。一些没用过的就先不说了,最近有点儿忙,暂且先追求下够用就行了,等用到了再补充到本文。







                                                                                                           如有遗漏部分,请亲留个言,thank u~





     

 




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn