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?
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.
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..
Convert Linebreaks with Razor
How I can convert linebreaks of a textbox multiple with razor?
Thanks...
Sören
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?
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 :-(
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
Does this help? http://stackoverflow.com/questions/4220381/replace-line-break-characters-with-br-in-asp-net-mvc-razor-view
Thanks,
I have found the solution. It's very easy:
@Html.Raw(@umbraco.library.ReplaceLineBreaks(@Model.property));
Sören
I know this is an older post, but it helps me to today, so thanks for share your solution Sören
/Dennis
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
Nice spot, Rob - I knew there must be a simpler way!
is working on a reply...