I'm not quite sure what the problem is, but the most common cause of this error is because you used the statement inside the "<% =%>" block, not the expression. Since the code inside the block "<% =%>" is placed in the call System.IO.TextWriter.Write, it must be an expression. Statements must be enclosed in blocks "<%%>", not "<% =%>".
The code you referenced should work fine on a partial view if it works on a "normal" view. Make sure the call RenderPartialis in the "<%%>" block, because it RenderPartialactually returns nothing, it does the rendering right there.
source
share