您的位置:首页 > 其它

[转]Pass a ViewBag instance to a HiddenFor field in Razor

2017-12-04 10:26 429 查看
本文转自:https://stackoverflow.com/questions/27456983/pass-a-viewbag-instance-to-a-hiddenfor-field-in-razor

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)

https://stackoverflow.com/questions/10179015/mvc-razor-html-helper-syntax-viewbag-in-html-hidden-object-parameter


Try casting the return value to
object
:

@Html.Hidden("hiddenDate", (object)ViewBag.myDate.ToString("dd.MM.yyyy"))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐