【发布时间】:2011-12-08 06:14:29
【问题描述】:
如果我在动态ViewBag 中有一个值,为什么我不能将它传递给一个方法?所以为了简单起见,假设我有ViewBag.SomeValue,并且我想将ViewBag.SomeValue 传递给HTML Helper。如果 HTML 助手接受动态作为变量,为什么不接受我的ViewBag.SomeValue?
@Html.SimpleHelper(ViewBag.SomeValue)
public static string SimpleHelper(this HtmlHelper html, dynamic dynamicString)
{
return string.Format("This is my dynamic string: {0}", dynamicString);
}
【问题讨论】:
-
你能显示一些代码吗?我在aspx模板和助手中使用动态,看起来没有问题。
-
我刚刚编辑了答案并添加了代码。
标签: c# asp.net-mvc asp.net-mvc-3 c#-4.0