This is a migrated thread and some comments may be shown as answers.

Editor not displaying formatted text correctly when html is loaded in to editor

9 Answers 649 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Morris
Top achievements
Rank 1
Morris asked on 11 Apr 2011, 11:16 PM
Hi folks,

I am having problems with the editor control where it allows me to enter data, format it correctly (bold etc) and save the data to a database. When I try to edit the text again in the editor it doesnt display the formatting correctly but displays the html tags surrounding the text i.e: <strong>working</strong>

The next time I save the data it appears in this format: &lt;strong&gt;working description&lt;/strong&gt;

This is the code I am using to display the text in the editor:

        <% Html.Telerik().Editor()
         .Name("Description")
         .Value(Model.Description)
         .Render();
        %>

//Code to the populate the model before saving to the database:
article.Description = collection["Description"];

When I display the code in my browser the text dislays properly formatted when it is viewed in the browser (after the first save to the db):

        <%=
HttpUtility.HtmlDecode(Model.Description)
        %>

After subsequent saves the text displays like so: <strong>working description</strong>

Can anyone help shed some light on this? Im really confused as to how to make this work properly

Cheers
Morris

9 Answers, 1 is accepted

Sort by
0
mahmoud
Top achievements
Rank 1
answered on 21 May 2011, 07:40 AM
The same problem Morris :-(
Could you solve it or any work around?
0
Jacob
Top achievements
Rank 1
answered on 06 Jun 2011, 01:08 AM
Hi all, got the same issue here, first save works great, using the encoded string to the db, retrieving it for display decoded and in raw format works great, but assigning it back for the edit just doesn't cut it, still renders with the HTML tags, it is almost as if one has to use the HTML.Raw helper when assigning the value, but haven't had any luck with that either......

Update: Sorted it out....
1. Do not encode your strings saving back to the db
2. Use standard binding when editing your strings
3. When displaying the content back to your "public view" then use HTML.Raw(Html.Raw(HttpUtility.HtmlDecode(model.value))) or add this to your controller classes

        public ActionResult Edit(int id)
        {
            MyClass theclass = db.test.Find(id);        
            theclass.html = System.Web.HttpUtility.HtmlDecode(theclass.html);
            return View(theclass);
        }
        public ViewResult Details(int id)
        {
            
            MyClass theclass = db.test.Find(id);
            theclass.html= System.Web.HttpUtility.HtmlDecode(theclass.html);
            return View(theclass);
        }


Hope this helps you guys, worked for me, stupid mistake from my side :-)
0
mahmoud
Top achievements
Rank 1
answered on 08 Jun 2011, 06:13 AM
Jacob, would you please explain what exactly you do to overcome this problem? I don't get your points :-)
0
Kko
Top achievements
Rank 1
answered on 09 Jun 2011, 09:08 AM
Hello,

Try this:
@{
              Model.Description = Server.HtmlDecode(Model.Description);
              Html.Telerik().EditorFor(model => model.Description)
                          .Name("Description")
                          .Encode(true)
                          .Tools(tools => tools
                              .Clear()
                              .Bold().Italic().Separator()
                              .InsertOrderedList().InsertUnorderedList().Separator()
                              .Indent().Outdent()
                          )
                          .Render();
             }
Hope this helps.
0
Jacob
Top achievements
Rank 1
answered on 09 Jun 2011, 10:04 AM
Hey there Mahmoud

Attached a really simple vs2010 example hope this helps

Regards
Jacob
0
mahmoud
Top achievements
Rank 1
answered on 09 Jun 2011, 09:28 PM
Thank you both Jacob and kko. both solutions work fine !
0
Travis
Top achievements
Rank 1
answered on 24 Aug 2011, 11:43 PM
Thank you Kko!!!  So frustrating that it does not work like you'd expect.
0
Kko
Top achievements
Rank 1
answered on 09 Sep 2011, 09:37 AM
Welcome guys.
Hope to reduce the "Sherlock Holmes" time :) a little bit.

Happy coding!
0
Loften
Top achievements
Rank 1
answered on 30 Nov 2012, 04:54 PM
Thanks much!  This worked for me!
Tags
Editor
Asked by
Morris
Top achievements
Rank 1
Answers by
mahmoud
Top achievements
Rank 1
Jacob
Top achievements
Rank 1
Kko
Top achievements
Rank 1
Travis
Top achievements
Rank 1
Loften
Top achievements
Rank 1
Share this question
or