Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Petras Surna 90 posts 144 karma points
    Apr 06, 2011 @ 08:21
    Petras Surna
    0

    How do you output text if an if condition is fulfilled?

    Some of my questions are embarassing, here's another.

    How do you output ordinary text if an if condition is fulfilled?

    eg

     if(@blogpost.blogImage.ToString().Length > 0)
     {
        @Model.MediaById(System.Convert.ToInt32(@blogpost.blogImage)).umbracoFile //ok
        <p>wow</p> //fails!
     }

     

  • Toni Becker 146 posts 425 karma points
    Apr 06, 2011 @ 12:02
    Toni Becker
    0

    try this

    @if(blogpost.blogImage.ToString() !="")

    {

    @Model.MediaById(System.Convert.ToInt32(@blogpost.blogImage)).umbracoFile //ok
    <p>wow</p> //fails!
    }
    else { <p>Sorry no content available</p>
    }

     

  • Alex 78 posts 136 karma points
    Apr 06, 2011 @ 12:59
    Alex
    0

    Hi Petras, I can't replicate your problem it works fine for me, do you get an error?

    You can force the Razor View engine to switch to Markup using the @: syntax

    @:<p>wow</p>
  • Petras Surna 90 posts 144 karma points
    Apr 07, 2011 @ 03:11
    Petras Surna
    0

    I am dsylexic, my original example actually works.

    There was a bug in another statement!

    Although I never knew about Alex's post.

  • Bruce Canino 21 posts 42 karma points
    Apr 11, 2011 @ 00:46
    Bruce Canino
    0

    Thank you very much for the @: syntax. I been banging my head with a problem of the markup.

     

    When I get more carma points, I give you a helpful click

Please Sign in or register to post replies

Write your reply to:

Draft