multiline text display in razor core
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
add a comment |
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
add a comment |
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
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
razor asp.net-core asp.net-core-mvc
asked Nov 25 '18 at 10:18
user2328625user2328625
8110
8110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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 <tags> and &#64; and <b> bold </b>
line 3</span>
add a comment |
Just use @Html.TextAreaFor(m => m.fieldName)
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 <tags> and &#64; and <b> bold </b>
line 3</span>
add a comment |
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 <tags> and &#64; and <b> bold </b>
line 3</span>
add a comment |
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 <tags> and &#64; and <b> bold </b>
line 3</span>
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 <tags> and &#64; and <b> bold </b>
line 3</span>
<span style="white-space: pre-line">line 1
line 2 with <tags> and &#64; and <b> bold </b>
line 3</span>
<span style="white-space: pre-line">line 1
line 2 with <tags> and &#64; and <b> bold </b>
line 3</span>
answered Nov 26 '18 at 7:07
itminusitminus
4,1081423
4,1081423
add a comment |
add a comment |
Just use @Html.TextAreaFor(m => m.fieldName)
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
add a comment |
Just use @Html.TextAreaFor(m => m.fieldName)
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
add a comment |
Just use @Html.TextAreaFor(m => m.fieldName)
Just use @Html.TextAreaFor(m => m.fieldName)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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