Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    Jun 06, 2013 @ 11:27
    René Andersen
    0

    Only show button if file is uploaded

    Hi everybody

    I am about to make a website about beer brewing. On some of the beers I upload a recipe as PDF. How do i make a Razor script that only show the "Download recipe" button when a file / PDF is uploaded?
    The code below is what I need to show up when a file / PDF is uploaded:

    <a href="@Model.recipe" class="btn btn-inverse btn-medium btn-rounded" target="_blank"><h6>Download recipe</h6></a>

    Thanks in advance.

    //René

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 06, 2013 @ 11:45
    Jeavon Leopold
    100

    Hi Rene,

    What an awesome thing to be building a website about! Is your "recipe" property of type upload or is it something else?

     If it is of type Upload then it would be like this:

    @{
       if (Model.HasValue("recipe")){
           <a href="@Model.recipe" class="btn btn-inverse btn-medium btn-rounded" target="_blank"><h6>Download recipe</h6></a>
       } 
    }

    Thanks,

    Jeavon

  • René Andersen 238 posts 684 karma points
    Jun 06, 2013 @ 12:39
    René Andersen
    0

    Hi Jeavon,

    You have just solved my problem again. :-) It worked perfectly.

    If you ever swing by Denmark then give me a hint and I will fill up the fridge with some of my latest brew.

    What if the property was something else than upload for example a textstring would that be made the same way?

    // René

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 06, 2013 @ 12:50
    Jeavon Leopold
    0

    Hi René,

    Great! I am coming to Denmark on Tuesday for #CG13, will you be there?

    Yes, it would be exactly the same way for a text string. If it was a media picker then it would be slightly different as you would need to lookup the Url from the media item.

    I would really recommend you take a look at the examples in the documentation for the property editors here Compare TextString to Media Picker for example.

    Thanks

    Jeavon,

    p.s. The other day you were using a Mvc Partial, today you are using a "classic" Razor macro, is there a reason for that?

  • René Andersen 238 posts 684 karma points
    Jun 06, 2013 @ 13:21
    René Andersen
    0

    Hi Jeavon,

    Unfortunately not but I will be in Sweden canoeing with my kids. :-)

    I will take a look at the examples.

    To be honest I am fairly new to Umbraco and Razor and therefore I use some part of the code from examples like "CultivRazorexample" the Mvc part. And the classic Razor is something that i have learned from a friend. I am still learning a lot and my sites keeps changing from the last project to the next.

    // René,

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 06, 2013 @ 14:11
    Jeavon Leopold
    0

    Ah cool, well I would say stick with the Mvc if you can. However, as you have probably found there are a lot more existing samples for "classic" razor macros. There are a load of useful Mvc docs here though.

  • René Andersen 238 posts 684 karma points
    Jun 06, 2013 @ 14:19
    René Andersen
    0

    I will definitely look at the Mvc docs and maybe use it even more in the future.

    I really appreciate your help and I hope that you will have a nice trip to Denmark. At the moment the weather is just perfect and the forecast looks promising for next week.

    Thanks again!

    // René,

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies