14

Is Response.Write() working with Razor?

I tried to use @Html.RenderAction but I'm getting the error:

CS1502: The best overloaded method match for 
'Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)'   
has some invalid arguments
stacker
  • 14,641
  • 17
  • 46
  • 74

1 Answers1

22

This is the correct syntax:

@{Html.RenderAction("Index", "Menu");}

Or just using Action:

@Html.Action("Index", "Menu")
stacker
  • 14,641
  • 17
  • 46
  • 74
  • 1
    stacker's got it. It's like using <%= to call a method that returns Void, you get a compiler error about not finding a correct overload. "@Foo" <==> "<%= Foo %>" and "@{Foo}" <==> "<% Foo %>" – Andrew Stanton-Nurse Aug 02 '10 at 15:37
  • In the MVC 3 RTM I get this 'No overload for method 'Write' takes 0 arguments' - so I'm not convinced it works anymore. Would love to be corrected though since Html.Action doesn't take a lambda and I'm forced to use RenderAction instead. [oh and I get this error whether I use a lambda or not] – Simon_Weaver Mar 11 '11 at 06:15
  • +1 I would only add that it is advertised as preferable to use RenderAction as it outputs to the response stream without string creation. – JasonCoder Aug 12 '11 at 19:13