当前位置: 代码迷 >> VC/MFC >> Part 三 ViewData and ViewBag in mvc
  详细解决方案

Part 三 ViewData and ViewBag in mvc

热度:108   发布时间:2016-05-02 03:38:31.0
Part 3 ViewData and ViewBag in mvc

ViewBag and ViewData is a mechanism(机制) to pass data from controller to view.

We use '@' symbol(符号) to switch between html and C# code.

Both ViewData and ViewBag are used to pass data from a controller to a view.

ViewData is a dictionary of object that are stored and retrieved()取回 using strings as keys.

ViewBag uses the dynamic feature that was introduced in to C#4. It allows an object to have properties dynamically added to it.

Both ViewData and ViewBag does not provide compile time error checking. For example, if you mis-spll keys or property names, you wouldn't get any compile time error. You get to know about the error only at runtime. Internally ViewBag properties are stored as name/value pairs in the ViewData dictionary.

 

  相关解决方案