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

I have this code in an MVC project using the WebForms viewer, and I'm trying to convert it to Spark. How can I conditionally name a partial and transmit its viewing data?

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

Tried this (to no avail, it displays partial in front of all other content):

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

<% 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 <test if = ""> the variation should work and produce almost identical code:

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

Maybe try to print $ {UserService.IsAuthenticated} and $ {Model.Post.IsDeleted} to be absolutely sure that the condition is not always true?


- , ... , "" - WebForms, Reply.ascx Reply.aspx? WebForms , HttpContext, , .

Spark, .

+6

if = ""

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

Twitter, , .ascx, .spark. , .ascx. Reply.ascx , , .

+1

Source: https://habr.com/ru/post/1710632/


All Articles