将字典放在Viewbag中

时间:2012-04-13 07:51:38

标签: asp.net-mvc-3 model-view-controller

我正在尝试在我的视图中访问词典。但是语法如下:

@{
    var indexList = Viewbag.IndexList as Dictionary<int,long>;
}

不起作用:The name 'Viewbag' does not exist in the current context

附: :尝试在Viewbag之前放置'@',仍然无法正常工作。

有人可以帮忙吗?提前致谢

2 个答案:

答案 0 :(得分:5)

不是ViewBag吗?

var indexList = ViewBag.IndexList as Dictionary<int,long>;

答案 1 :(得分:0)

尝试这种方式:

var indexList = this.ViewBag.IndexList as Dictionary<int,long>;