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()); } 

This gives me an 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 this? Thanks.

+7
source share
2 answers

The problem may be that the compiler cannot select the correct type.

Try also changing it:

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

Have a look at this stackoverflow question: fooobar.com/questions/91107 / ...

+18
source

Yes, that helped. Thanks for the answer.

0
source

Source: https://habr.com/ru/post/921569/


All Articles