将数据从控制器传递到视图
我有一个愚蠢的问题: 在我的控制器中,我设置:
ViewBag.totalCount = 20
在我想要调用的视图中:
@Html.Pager(8, 1, @ViewBag.totalCount);
但我认为 ViewBag 未被识别,因为整个方法调用在 VS 中带有下划线。它必须是简单的东西。请问我怎样才能这样呢?谢谢!
I have a silly question :
In my controller I set :
ViewBag.totalCount = 20
In the view I want to call:
@Html.Pager(8, 1, @ViewBag.totalCount);
but I think that ViewBag is not recognized as the whole method call is underlined in VS. It has to be something simple. How can I so it please ? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需
假设它是一个
int
(您需要进行强制转换,因为它将是动态
)。 ViewBag 前面没有@
(因为您已经在代码中),并且如果寻呼机返回非 void,您可以省略尾随的;
Just need
assuming it's an
int
(you need to cast as it will bedynamic
). No@
in front of ViewBag (since you're already in code) and, if pager returns non-void, you can omit the trailing;
它应该是
ViewBag.totalCount
,而不是@ViewBag.totalCount
。It should be
ViewBag.totalCount
, not@ViewBag.totalCount
.