This script works well in MVC 1, however I get "invalid arguments error" in MVC2: this.menuItems.Add("action", Html.ActionLink("action", "view", "Controller"));
1 Answer
In MVC2, ActionLink returns an MvcHtmlString, and menuItems.Add likely expects a string. So this should work:
this.menuItems.Add("action",
Html.ActionLink("action", "view", "Controller").ToString());
7 Comments
jordanbtucker
Does anyone else find it strange that MvcHtmlString doesn't include an implicit conversion operator for string?
jordanbtucker
@user373721. No problem. (May I ask that you mark it as the answer. Thanks.)
hncl
How can I do that, I searched but did not find an answer, thanks
marcind
@Jordan that was a concious decision. Implicit conversion operators can be confusing and we wanted to enforce the difference between encoded and unencoded html strings.
jordanbtucker
@user373721. It's a checkbox underneath the vote control. No prob if you can't find it.
|