asp.net-mvcspark-view-engine

How to use Html.RenderAction in SparkView Engine?


I am getting an error when I use it like this

!{Html.RenderAction("Action", "Controller")}

I had to switch to webforms view engine and replace it with

<% Html.RenderAction("Action", "Nav"); %>

to get it to work.

The error I am getting is "Cannot convert void to char"


Solution

  • <% Html.RenderAction("Action", "Nav"); %>
    

    is the same as

    # Html.RenderAction("Action", "Nav");
    

    in Spark syntax. {} expression expects a result to be returned and written to the stream; RenderAction does not return nothing, it writes to the stream itself. That's why you have to call it inside code block and cannot do this inside expression.