Click here to Skip to main content
14,244,070 members
Rate this:
Please Sign up or sign in to vote.
Please find attached the html code and the printscreen of my problem. When I write something in ckeditor, and apply styling with html tags, it saved the text with HTML tags, and not just the text itself, in this case just CONTENT SAMPLE TEXT. It also applies the styling for certain html tags in backgound, and does not show them like <pre><p>CONTENT SAMPLE TEXT</p>


<div class="form-group">
      @Html.LabelFor(model => model.LongDescription1, htmlAttributes: new { @class = "control-label col-md-2" })
      <div class="col-md-10">

         @Html.TextAreaFor(model => model.LongDescription1, new { @id = "LongDescription1", @class = "form-control", @rows = "200" })



          @Html.ValidationMessageFor(model => model.LongDescription1, "", new { @class = "text-danger" })
          CKEDITOR.replace("LongDescription1", { htmlEncodeOutput: true });


      </div>
  </div>


What I have tried:

No mention is made of what the poster has tried.
Posted
Updated 4-Aug-17 5:44am
v2
Comments
Richard Deeming 3-Aug-17 9:10am
   
Not clear at all.

If you want the text without any formatting, then use a <textarea>, not an HTML editor.

If you want to keep the formatting, then you need to keep the HTML tags. That's how the formatting is applied.
ddgjgj 4-Aug-17 3:29am
   
So , the code is above. That is my Create View in MVC. What i want is , to have ckeditor for field LongDescription1 , so if i type there SAMPLE TEXT and if I do some html formatting there , example SAMPLE TEXT , it should save the value SAMPLE TEXT in bold , in the field LongDescription1. And at the Edit view , if i try to edit that text , if should show me the exact formatted text , and not like in my case , example : ITALIC , i want just to show ITALIC in italic style in editor , and then try to edit that text .And in the index page , it should me show the exast formatted text how i saved it . First of all , should i add [AllowHtml]

in this field public string LongDescription1 { get; set; } .I would be thankful for any help.
Rate this:
Please Sign up or sign in to vote.

Solution 1

CKEditor is a HTML based editor. All the richness you see gained using HTML tags and their attributes... If you remove the HTML part you get plain text...
   
Comments
ddgjgj 4-Aug-17 3:29am
   
So , the code is above. That is my Create View in MVC. What i want is , to have ckeditor for field LongDescription1 , so if i type there SAMPLE TEXT and if I do some html formatting there , example SAMPLE TEXT , it should save the value SAMPLE TEXT in bold , in the field LongDescription1. And at the Edit view , if i try to edit that text , if should show me the exact formatted text , and not like in my case , example : ITALIC , i want just to show ITALIC in italic style in editor , and then try to edit that text .And in the index page , it should me show the exast formatted text how i saved it . First of all , should i add [AllowHtml]

in this field public string LongDescription1 { get; set; } .I would be thankful for any help.
Rate this:
Please Sign up or sign in to vote.

Solution 2

If I've understood your comment correctly, the problem is not with editing the HTML, but with displaying it again.

When you use:
@Model.LongDescription1
the output is automatically HTML-encoded. This is to protect against cross-site scripting vulnerabilities.

So, if you've entered: "This is a test", the output will be: "<b>This</b> is a <i>test</i>"

To have your output treated as HTML, you need to use the Html.Raw[^] helper:
@Html.Raw(Model.LongDescription1)

NB: You will need to ensure that users are not able to inject malicious HTML / Javascript into other users' views.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100