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

How to avoid duplicate encode in kendoui editor?

3 Answers 237 Views
Editor
This is a migrated thread and some comments may be shown as answers.
LI
Top achievements
Rank 1
LI asked on 23 Dec 2013, 04:11 PM
I hope the editor can be encoded because I want to post the editor text to the controller,but I find that when I refresh the page(click F5),the editor encode the text again.My Model.Body also contains html mark: For example, first Time enter the page is OK,and show "My Model Body Is Here",and I refresh the page it show the html mark like below,but I just want to encode only one time,I also use no cache but it do not work.Third time I refresh the page,it encode again,and show <table><tbody>...
Model:
 
//after search,my Model.Body is here
 <table>
 <tbody>
 <tr><td align="center" style="font-weight:bold;">
 <span style="background-color:#ccff33;">My Model Body Is Here</span>
 </td></tr>
 </tbody>
 </table>
View:
 
  @(Html.Kendo().Editor()
  .Name("Body")
  .Tools(tools => tools.Clear()
  .Bold().Italic().Underline().Strikethrough()
  .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
  .InsertUnorderedList().InsertOrderedList()
  .Outdent().Indent()
  .CreateLink().Unlink()
  .InsertImage()
  .SubScript()
  .SuperScript()
  .ViewHtml()
  .FontName()
  .FontSize()
   .FontColor().BackColor()
   )
   .HtmlAttributes(new { style = "width:90%;height:500px" })
   .Value(Model.Body))
Controller:
 
 [OutputCache(Duration = 0)]
 public ActionResult Index(int id=0)
 {
 return View(ModelRepository.GetModelById(id));
 }

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 24 Dec 2013, 09:00 AM
Hello Li,

This is caused by the default encoding of the editor, when the page is fetched from the browser bfcache. In order to resolve that, set Encoded(false) in the view, and indicate that the field will contain HTML in the model, by setting the [AllowHtml] attribute.

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
LI
Top achievements
Rank 1
answered on 24 Dec 2013, 03:53 PM
Hi,Alex Gyoshev.You say that the page is fetched from the browser bfcache.But I have set no cache in controller.Why do it not work?
[OutputCache(Duration = 0)]
Can I set no bfcache?If I can,I think it will work well.
0
Alex Gyoshev
Telerik team
answered on 25 Dec 2013, 08:19 AM
Hello Li,

According to this post in StackOverflow, the bfcache is cleared if you attach an unload handler to the body, like this:

    <body onunload="">

This will disable the bfcache and the problem will perish, however it will also mean that the regular browser behavior will be changed (i.e. when the page is not fetched from the bfcache, field values may be lost upon refresh / navigation).

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Editor
Asked by
LI
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
LI
Top achievements
Rank 1
Share this question
or