Passing data from controller to view

让人想犯罪 __ 提交于 2019-12-11 05:28:27

问题


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!


回答1:


Just need

@Html.Pager(8, 1, (int)ViewBag.totalCount)

assuming it's an int (you need to cast as it will be dynamic). No @ in front of ViewBag (since you're already in code) and, if pager returns non-void, you can omit the trailing ;




回答2:


It should be ViewBag.totalCount, not @ViewBag.totalCount.



来源:https://stackoverflow.com/questions/7272697/passing-data-from-controller-to-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!