Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 22, 2011 @ 11:17
    Sören Deger
    1

    Convert Linebreaks with Razor

    How I can convert linebreaks of a textbox multiple with razor?

     

    Thanks...

     

    Sören

  • alimac 182 posts 371 karma points
    Dec 22, 2011 @ 11:28
    alimac
    0

    I'm not sure how you'd do this in razor but I know that if you click on the 'insert umbraco page field' in the template editor, you can click a checkbox to convert line breaks to <br /> tags automatically. Is there any way you can use this to save you having to do the conversion in razor?

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 22, 2011 @ 11:35
    Sören Deger
    0

    I must get the value of a textbox multiple in razor and not in a template.

    With xslt this is the solution: <xsl:value-of select="umbraco.library:ReplaceLineBreaks(property)" disable-output-escaping="yes"/>

    In a template it works with <umbraco:Item field="property" convertLineBreaks="true" runat="server" />, but I need this function in Razor :-(

  • Rich Green 2246 posts 4008 karma points
    Dec 22, 2011 @ 11:37
    Rich Green
    2

    Hi,

     

    Just use umbraco.library:ReplaceLineBreaks() the Umbraco Library will work in Razor, not sure if you have to ad a reference as I don't use Razor at the moment.

     

    Rich

  • alimac 182 posts 371 karma points
    Dec 22, 2011 @ 11:38
  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 22, 2011 @ 11:50
    Sören Deger
    12

    Thanks,

    I have found the solution. It's very easy:

    @Html.Raw(@umbraco.library.ReplaceLineBreaks(@Model.property));

     

    Sören

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 14, 2013 @ 21:15
    Dennis Aaen
    0

    I know this is an older post, but it helps me to today, so thanks  for share your solution Sören

    /Dennis

  • Rob 43 posts 79 karma points
    Dec 16, 2013 @ 01:33
    Rob
    2

    It may be even easier..
    I needed to convert a string from a multiline text into text with <br /> tags for the line return.. - the above method did't work with umbraco.fields..

    so

    @Umbraco.Field("streetAddress", convertLineBreaks:true);

    Far too easy :)

    It showed up in the available attributes/ named arguments in visual studio intellisence. (I love that stuff!!!)

    HTH

    Rob

     

     

     

  • alimac 182 posts 371 karma points
    Dec 16, 2013 @ 11:10
    alimac
    0

    Nice spot, Rob - I knew there must be a simpler way!

Please Sign in or register to post replies

Write your reply to:

Draft