multiline text display in razor core












1















I've taken multiline input with textarea html tag eg:



line 1
line 2 with <tags> and @ and <b> bold </b>
line 3


but how can I later display this?



If I use:



@Html.DisplayFor(m => m.MultilineText2)


it handles the special characters fine, but not the linebreak



If I use:



@Html.Raw(Model.MultilineText2.Replace(Environment.NewLine, "<br/>"))


it handles the linebreak, but not the special chars.



I just want the result to appear exactly as the user entered it (exactly as you see it in the example above)










share|improve this question



























    1















    I've taken multiline input with textarea html tag eg:



    line 1
    line 2 with <tags> and @ and <b> bold </b>
    line 3


    but how can I later display this?



    If I use:



    @Html.DisplayFor(m => m.MultilineText2)


    it handles the special characters fine, but not the linebreak



    If I use:



    @Html.Raw(Model.MultilineText2.Replace(Environment.NewLine, "<br/>"))


    it handles the linebreak, but not the special chars.



    I just want the result to appear exactly as the user entered it (exactly as you see it in the example above)










    share|improve this question

























      1












      1








      1








      I've taken multiline input with textarea html tag eg:



      line 1
      line 2 with <tags> and @ and <b> bold </b>
      line 3


      but how can I later display this?



      If I use:



      @Html.DisplayFor(m => m.MultilineText2)


      it handles the special characters fine, but not the linebreak



      If I use:



      @Html.Raw(Model.MultilineText2.Replace(Environment.NewLine, "<br/>"))


      it handles the linebreak, but not the special chars.



      I just want the result to appear exactly as the user entered it (exactly as you see it in the example above)










      share|improve this question














      I've taken multiline input with textarea html tag eg:



      line 1
      line 2 with <tags> and @ and <b> bold </b>
      line 3


      but how can I later display this?



      If I use:



      @Html.DisplayFor(m => m.MultilineText2)


      it handles the special characters fine, but not the linebreak



      If I use:



      @Html.Raw(Model.MultilineText2.Replace(Environment.NewLine, "<br/>"))


      it handles the linebreak, but not the special chars.



      I just want the result to appear exactly as the user entered it (exactly as you see it in the example above)







      razor asp.net-core asp.net-core-mvc






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 10:18









      user2328625user2328625

      8110




      8110
























          2 Answers
          2






          active

          oldest

          votes


















          1














          If I understand correctly, what you want is to encode everything else except the linebreakers. But you don't need to care about that. Since there's a standard way by white-space :




          pre-line



          Sequences of white space are collapsed. Lines are broken at newline characters, at
          , and as necessary to fill line boxes.




          So, simply adding a white-space: pre-line will work:



          <span style="white-space: pre-line">@Html.DisplayFor(m => m.MultilineText2)</span>


          the generated html will be :






          <span style="white-space: pre-line">line 1
          line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
          line 3</span>





          enter image description here






          share|improve this answer































            1














            Just use @Html.TextAreaFor(m => m.fieldName)






            share|improve this answer
























            • Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

              – user2328625
              Nov 26 '18 at 13:04











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466535%2fmultiline-text-display-in-razor-core%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            If I understand correctly, what you want is to encode everything else except the linebreakers. But you don't need to care about that. Since there's a standard way by white-space :




            pre-line



            Sequences of white space are collapsed. Lines are broken at newline characters, at
            , and as necessary to fill line boxes.




            So, simply adding a white-space: pre-line will work:



            <span style="white-space: pre-line">@Html.DisplayFor(m => m.MultilineText2)</span>


            the generated html will be :






            <span style="white-space: pre-line">line 1
            line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
            line 3</span>





            enter image description here






            share|improve this answer




























              1














              If I understand correctly, what you want is to encode everything else except the linebreakers. But you don't need to care about that. Since there's a standard way by white-space :




              pre-line



              Sequences of white space are collapsed. Lines are broken at newline characters, at
              , and as necessary to fill line boxes.




              So, simply adding a white-space: pre-line will work:



              <span style="white-space: pre-line">@Html.DisplayFor(m => m.MultilineText2)</span>


              the generated html will be :






              <span style="white-space: pre-line">line 1
              line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
              line 3</span>





              enter image description here






              share|improve this answer


























                1












                1








                1







                If I understand correctly, what you want is to encode everything else except the linebreakers. But you don't need to care about that. Since there's a standard way by white-space :




                pre-line



                Sequences of white space are collapsed. Lines are broken at newline characters, at
                , and as necessary to fill line boxes.




                So, simply adding a white-space: pre-line will work:



                <span style="white-space: pre-line">@Html.DisplayFor(m => m.MultilineText2)</span>


                the generated html will be :






                <span style="white-space: pre-line">line 1
                line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
                line 3</span>





                enter image description here






                share|improve this answer













                If I understand correctly, what you want is to encode everything else except the linebreakers. But you don't need to care about that. Since there's a standard way by white-space :




                pre-line



                Sequences of white space are collapsed. Lines are broken at newline characters, at
                , and as necessary to fill line boxes.




                So, simply adding a white-space: pre-line will work:



                <span style="white-space: pre-line">@Html.DisplayFor(m => m.MultilineText2)</span>


                the generated html will be :






                <span style="white-space: pre-line">line 1
                line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
                line 3</span>





                enter image description here






                <span style="white-space: pre-line">line 1
                line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
                line 3</span>





                <span style="white-space: pre-line">line 1
                line 2 with &lt;tags&gt; and &amp;#64; and &lt;b&gt; bold &lt;/b&gt;
                line 3</span>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 26 '18 at 7:07









                itminusitminus

                4,1081423




                4,1081423

























                    1














                    Just use @Html.TextAreaFor(m => m.fieldName)






                    share|improve this answer
























                    • Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

                      – user2328625
                      Nov 26 '18 at 13:04
















                    1














                    Just use @Html.TextAreaFor(m => m.fieldName)






                    share|improve this answer
























                    • Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

                      – user2328625
                      Nov 26 '18 at 13:04














                    1












                    1








                    1







                    Just use @Html.TextAreaFor(m => m.fieldName)






                    share|improve this answer













                    Just use @Html.TextAreaFor(m => m.fieldName)







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 25 '18 at 11:00









                    Jeime Anne VillanuevaJeime Anne Villanueva

                    364




                    364













                    • Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

                      – user2328625
                      Nov 26 '18 at 13:04



















                    • Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

                      – user2328625
                      Nov 26 '18 at 13:04

















                    Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

                    – user2328625
                    Nov 26 '18 at 13:04





                    Thanks for the reply, I've tested this, but this is not the desired result. I already got the input from a textarea tag, now I just want to display it as non-editable text on another page.

                    – user2328625
                    Nov 26 '18 at 13:04


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466535%2fmultiline-text-display-in-razor-core%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin