问题描述
我在我的默认的HomeController将值设置到 Viewbag.message
,并成功地在我的共享/ _Layout.cshtml $显示它C $ C>。
I've set a value into Viewbag.message
in my default HomeController and successfully display it in my Shared/_Layout.cshtml
.
之后,我又加和的TestController在视图的TestController, Viewbag.message
似乎是空。我想知道什么是错。
After that I added another TestController and in the TestController view, Viewbag.message
seems to be null. May I know what's wrong with it.
纠正我,如果我错了,从我的理解 Viewbag.Message
应提供来自全国各地的地方呢?
Correct me if I'm wrong,from my understanding Viewbag.Message
should be available from all over the places?
推荐答案
ViewBag是一个动态的属性,它利用了新的动态特性在C#4.0。
基本上它是围绕的ViewData的包装,也用于从控制器的数据传送到相应的视图。
ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.Basically it is a wrapper around the ViewData and also used to pass data from controller to corresponding view.
- 这是生活中也仅在当前请求所在。如果则会发生重定向它的值变为零。
- 它不要求强制类型转换复杂的数据类型。
下面是显示持久性机制不同的汇总表。
<一href=\"http://www.$c$cproject.com/Articles/556995/Model-view-controller-MVC-Interview-questions-and\">Credit:$c$cProjectArticle
Below is a summary table which shows different mechanism of persistence. Credit:CodeProjectArticle
这篇关于MVC从另一个控制器传递ViewBag值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!