locked
Trying to pass line-break element <br> to SPAN element gets encoded RRS feed

  • Question

  • User-687931224 posted

    Sorry if this seems like a stupid question and it probably is. But in VSWeb 2012 I am constructing a string that will appear in a SPAN element. I wish to pass <br> to allow line breaks to appear in the browser. Like so...

    Message += lst.Item("list_id") & " " & lst.Item("list_api_identifier") & lst.Item("list_description") & "<br>"

    Displaying the Message in Razor view as @Message, the <br> element is getting encoded to &lt;br&gt; in the page source.

    How do I allow the unencoded <br> to pass through to the page source?

    (yea I know it is VB...please no flames)

    Thanks

    Wednesday, June 11, 2014 3:29 PM

Answers

  • User-687931224 posted

    OK here is an update. After trying to pass \r\n to also create a line-break in a span (which did not work either), I finally tried using vbCrLf a Visual Basic constant for Carriage Return/Line-Feed and now my text displays nicely formatted with line breaks.

    Thanks for the reply

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 12, 2014 10:34 AM

All replies

  • User-991316286 posted

    try below 

    <span style="white-space: pre-line">@Message</span>

    check Replace line break characters with <br /> in ASP.NET MVC Razor view

    Thursday, June 12, 2014 12:34 AM
  • User-687931224 posted

    Thanks for the repy damithSL.

    I just tried that and here is what the page source looks like...

    <span style="white-space: pre-line">1656 TEST_USERSTest Users&lt;br/&gt;1331 fishing2013Fishing Enthusiasts&lt;

    I guess it didn't work.

    Thursday, June 12, 2014 7:03 AM
  • User-687931224 posted

    OK here is an update. After trying to pass \r\n to also create a line-break in a span (which did not work either), I finally tried using vbCrLf a Visual Basic constant for Carriage Return/Line-Feed and now my text displays nicely formatted with line breaks.

    Thanks for the reply

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 12, 2014 10:34 AM