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

How to display html encoded data into MVC Editor

1 Answer 245 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.
Avdut
Top achievements
Rank 1
Avdut asked on 11 Nov 2010, 05:21 PM
For the last 3 days i m fighting with telerik mvc Editor and still no success.............
I am having a Form in which telrik Editor is there and I want to display HTML encoded data in it but all it shows is &amp &lt &gt and so on.........

<% Html.Telerik().Editor().Name("Editor")
                                .Tools((p)=> { p.Clear(); p.FormatBlock().Bold().Italic().Underline();
                                })
                                .Value(()=>
                                    {%>                                
                         
                        <%: HttpUtility.HtmlEncode(ViewData["Description"]) %>
                        <%--<strong>Hello world!</strong>--%>
 
                                    <%}
                                )
                                .Render();
                                %>

this is not working for me But if I put hardcoded value then it is rendered properly............

please suggest me some solution for the same

1 Answer, 1 is accepted

Sort by
0
ori
Top achievements
Rank 1
answered on 04 Dec 2010, 12:40 AM
Hi,

In the last week i was busy with the same issue, here is what i did:
when you present the data i have done:
Controller:
    var html = HttpUtility.HtmlDecode(page.Description);
    page.Description = html.IndentHtml();
View:
<%=Model.Page.Description%>
when saving the data i have done:
View:
<% Html.Telerik().Editor()
       .Name("Description")
       .Value(()=>
       {
       %>
 
       <%
       })
       .Render(); %>
controller:
you dont need to do anything.

the editor save the HTMLencoded in the db.
then you need to read it from DB and present it in the view, you need to decode it.

I have tested the code for java-script injections and when you write html code he will present you html code back in the view.

hope it helps

Ori

Tags
Editor
Asked by
Avdut
Top achievements
Rank 1
Answers by
ori
Top achievements
Rank 1
Share this question
or