Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering Html.Hidden helper with custom value

I have the following razor markup:

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

It gives me error:

'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.

How can I fix it? Thanks.

like image 481
Maxim V. Pavlov Avatar asked Jul 28 '12 14:07

Maxim V. Pavlov


1 Answers

The problem might be that the compiler cannot choose the correct type.

Try changing it too:

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

Look at this stackoverflow question: https://stackoverflow.com/a/3822588/950890

like image 150
Fredrik Sundmyhr Avatar answered Nov 11 '22 02:11

Fredrik Sundmyhr