What's the equivalent syntax for this MVC view code in Spark?

asp.net-mvc, spark-view-engine

Solution

The

<% if (UserService.IsAuthenticated && !Model.Post.IsDeleted) { %>
    <% Html.RenderPartial("Reply", new ReplyViewModel { Id=Model.Post.PostId, CssClass="respond" }); %>
<% } %>

and

<if condition="UserService.IsAuthenticated && !Model.Post.IsDeleted">
    #Html.RenderPartial("Reply", new ReplyViewModel { Id=Model.Post.PostId, CssClass="respond" });
</if>

and the <test if=""> variation should all work and produce nearly identical code:

if (UserService.IsAuthenticated && !Model.Post.IsDeleted) 
{ 
    Html.RenderPartial("Reply", new ReplyViewModel { Id=Model.Post.PostId, CssClass="respond" });
}

Maybe try outputting ${UserService.IsAuthenticated} and ${Model.Post.IsDeleted} to be absolutely certain the condition isn't always true?

Okay - confirmed in another medium that's incorrect... Is it possible the "Reply" partial is a WebForms view like Reply.ascx or Reply.aspx? There is an issue with WebForms in that it's output by default will go directly to the current HttpContext response output, which makes it difficult to interleave those partials with view engines that spool or layer output.

There's a way to work around that in one of the Spark samples, but it's a bit tricky.

Problem

I've got this code in an MVC project using the WebForms view engine and I'm trying to convert it over to Spark. How can I conditionally call a partial and pass it view data? ``` <% if (UserService.IsAuthenticated && !Model.Post.IsDeleted) { %> <% Html.RenderPartial("Reply", new ReplyViewModel { Id=Model.Post.PostId, CssClass="respond" }); %> <% } %> ``` Tried this (to no avail, it renders the partial before all other content): ``` <if condition="UserService.IsAuthenticated && !Model.Post.IsDeleted"> #Html.RenderPartial("Reply", new ReplyViewModel { Id=Model.Post.PostId, CssClass="respond" }); </if> ```

Original source