Copied to clipboard

Flag this post as spam?

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


  • Pete 213 posts 285 karma points
    Mar 16, 2013 @ 17:16
    Pete
    0

    Replacing characters in html string using razor

    I can't get this line to produce correctly in HTML

    linkhtml = @Model.bodyText + "<a href=\"" + @Model.downloadLink.First.File + "\" class=pdficon target=_blank><img src='/images/pdf.gif' /></a>";

    It keeps dropping the / on the img tag, so it doesn't close it.

    This is the output:

    <a class="pdficon" target="_blank" href="mypdf.pdf">
       <img src="/images/pdf.gif">
    </a>
  • Sahan Rodrigo 25 posts 97 karma points
    Mar 18, 2013 @ 11:35
    Sahan Rodrigo
    0

    Hi Pete - According to my experience, the output is correct, because you can't see img closing tag "</img>" or </> in the source. 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 14:06
    Jan Skovgaard
    0

    @Sahan that's not quite true. If Pete is trying to write valid xhtml output then the <img> tag needs to be closed. If he's using html5 it's not a big deal though. However I still prefer the stricter syntax closing tags like in xhtml.

    @Pete Don't know if you perhaps need to escape the / sign?

    /Jan

  • Jais Edelmann 45 posts 126 karma points
    Mar 26, 2013 @ 18:28
    Jais Edelmann
    0

    You should be able to solve this by using html.raw or just merge the strings inside a codeblock

    @{

    var myString = "<a href=\""+Model.downloadLink.First.File+ \"" class=pdficon target=_blank><img src='/images/pdf.gif' /></a>";

    }


    Visit some link right here @myString and continue on

    Also in your example your \ is located 1 step to late after file url, i would also recommend using " around class and target including src of the img.

  • 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