Reputation: 7445
Like in topic. It is possible to do it? Or make something to use ViewBag items in place where we need no dynamic item?
Upvotes: 0
Views: 2688
Reputation: 13150
The best way is to create View model
and use that model
in your View
rather then ViewBag
.
Upvotes: 4
Reputation: 33865
It is probably not preferable, since you probably should use a model in that case, but in the view, you can always cast the viewbag property into a type, if you need it to be an int for instance,
int number = (int)ViewBag.MyNumber;
Upvotes: 2
Reputation: 60493
If you can't use a dynamic item, just declare a variable with the ViewBag's "static" type :
@IList<MyType> mylist= ViewBag.ListOfItemsOfMyType;
and use mylist
Upvotes: 1