11

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.

2
  • What is the type of Model? dynamic? Commented Jul 28, 2012 at 14:25
  • Yes, the view's Model is not strongly typed. Commented Jul 28, 2012 at 18:17

1 Answer 1

22

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.