使用自定义值呈现Html.Hidden帮助器

时间:2012-07-28 14:19:37

标签: asp.net-mvc razor

我有以下剃须刀标记:

@{
    var initValue = @Html.Raw(new JavaScriptSerializer().Serialize(Model));
    @Html.Hidden("initial-namings-data", initValue.ToString());
}

它给了我错误:

'System.Web.Mvc.HtmlHelper' has no applicable method named 'Hidden' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

我该如何解决?感谢。

1 个答案:

答案 0 :(得分:18)

问题可能是编译器无法选择正确的类型。

尝试更改它:

@Html.Hidden("initial-namings-data", (string)initValue.ToString());

请查看此stackoverflow问题:https://stackoverflow.com/a/3822588/950890