Transferring data from the controller for viewing

I have a stupid question: In my controller, I installed:

ViewBag.totalCount = 20 

In the view I want to call:

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

but I think the ViewBag is not recognized as the whole method call is underlined in VS. It should be something simple. How do I like it so much? Thanks!

+1
source share
2 answers

Just need

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

assuming it is int (you need to specify that it will be dynamic ). There is no @ before the ViewBag (since you are already in the code), and if the pager returns a non-void, you can omit the final one ;

+6
source

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

0
source

Source: https://habr.com/ru/post/1415486/


All Articles