本文转自: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"))

[转]Pass a ViewBag instance to a HiddenFor field in Razor的更多相关文章

  1. viewbag

    How does ViewBag in ASP.NET MVC work behind the scenes? https://stackoverflow.com/a/16950197/3782855 ...

  2. 【总文档】rac增加新节点的方法步骤 How to Add Node/Instance or Remove Node/Instance in 10gR2, 11gR1, 11gR2 and 12c Oracle Clusterware and RAC

    [总文档]How to Add Node/Instance or Remove Node/Instance in 10gR2, 11gR1, 11gR2 and 12c Oracle Clusterw ...

  3. Java SE 8 docs——Static Methods、Instance Methods、Abstract Methods、Concrete Methods和field

    一.Static Methods.Instance Methods.Abstract Methods.Concrete Methods ——Static Methods:静态方法 ——Instance ...

  4. C# ftp 图片上传多快好省

    前言 此篇讲到的是图片上传功能,每个网站必定会有这样类似的功能,上传文件.上传图片等等.那么接下来,看看我们EF+uploadfile+ftp如何玩转上传图片吧 效果预览 具体实现 一个简单数据库 只 ...

  5. iOS编码规范

      The official raywenderlich.com Objective-C style guide.   This style guide outlines the coding con ...

  6. EF DI & MVC

    The Repository Pattern with EF Code First & Dependency Injection in ASP.NET MVC3 Ray_Liang, 5 Ju ...

  7. EF UoC

    The Repository Pattern with EF Code First & Dependency Injection in ASP.NET MVC3 Ray_Liang, 5 Ju ...

  8. Python自动化之django的ORM操作——Python源码

    """ The main QuerySet implementation. This provides the public API for the ORM. " ...

  9. ExtJS笔记 Field

    Fields are used to define what a Model is. They aren't instantiated directly - instead, when we crea ...

随机推荐

  1. RabbitMQ 消息队列 DEMO

    1. 引用 RabbitMQ.Client.5.1.0 2. http://localhost:15672/ public class TestController : ApiController { ...

  2. SQL分组合并

    STUFF ( character_expression , start , length ,character_expression ) select TcodMedInst_GUID,stuff( ...

  3. Python3------装饰器详解

    装饰器 定义:本质是函数.(装饰其他函数)就是为其他函数添加附加功能 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 理解装饰器前提条件: 1.函数即"变量&qu ...

  4. C#构造方法(函数)

    一.概括 1.通常创建一个对象的方法如图: 通过  Student tom = new Student(); 创建tom对象,这种创建实例的形式被称为构造方法. 简述:用来初始化对象的,为类的成员赋值 ...

  5. Xml 序列化和反序列化

    xml序列化帮助类 using System.IO; using System.Xml; using System.Xml.Serialization; public class XmlHelper ...

  6. 华为交换机 查看 ip和mac对应关系

    IPv4: display arp IPv6: display ipv6 neighbors

  7. BZOJ 1003--[ZJOI2006]物流运输(最短路)

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 10034  Solved: 4403 Description ...

  8. Swift里字符串(五)Native strings

    Native strings have tail-allocated storage, which begins at an offset of nativeBias from the storage ...

  9. Storm累计求和Demo并且在集群上运行

    打成jar包放在主节点上去运行. import java.util.Map; import backtype.storm.Config; import backtype.storm.StormSubm ...

  10. yum安装报错:Failure when receiving data from the peer

    系统:Centos6.9 操作:yum install -y *.rpm 报错信息: Transaction Summary ===================================== ...