本文转自:
You are getting this error because ViewBag is dynamic type. You can use ViewModel instead of ViewBag to solve this problem.
Alternatively you can use following or plain html as suggested by iceburg:
@Html.Hidden("id", (string)ViewBag.PortfolioId)
Try casting the return value to object
:
@Html.Hidden("hiddenDate", (object)ViewBag.myDate.ToString("dd.MM.yyyy"))