Copied to clipboard

Flag this post as spam?

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


  • jonok 258 posts 474 karma points
    Dec 10, 2014 @ 10:44
    jonok
    0

    Ampersand always getting encoded in razor

    I'm using Umbraco 7.2 razor, and I'm trying to use imagegen with an opengraph tag, but the querystring ampersand (eg. "&width=380") always gets converted into '&' which ends up breaking imagegen and loading the full size image. Am I missing something simple to fix this problem? This is my code:

    <meta property="og:image" content="http://@HttpContext.Current.Request.Url.Host/imageGen.ashx?image=@mediaItem.Url&amp;width=380"/>
  • Dan Lister 415 posts 1970 karma points c-trib
    Dec 10, 2014 @ 10:53
    Dan Lister
    100

    Hi Jonok,

    Correct me if I'm wrong but isn't your code outputting "& amp;"? Can't you just use "&" instead?

    <meta property="og:image" content="http://@HttpContext.Current.Request.Url.Host/imageGen.ashx?image=@mediaItem.Url&width=380 "/>
    

    I guess if that doesn't work, you could always use Html.Raw() in your content attribute:

    @Html.Raw(mediaItem.Url)
    

    Hope that helps.

    Thanks, Dan.

  • jonok 258 posts 474 karma points
    Dec 10, 2014 @ 10:58
    jonok
    1

    Wow - I've been working too long. You're right - I was already using &amp; in the razor. What an idiot :)

Please Sign in or register to post replies

Write your reply to:

Draft