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

[Solved] Encoding Problem in Telerik Editor

2 Answers 54 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.
sushant
Top achievements
Rank 1
sushant asked on 03 Oct 2012, 11:41 AM
Hi,
I am using telerik's Editor to accept formatted text from user in MVC3.
 I am facing encoding and decoding related problem in that.

The code snippet is :
. View : 
@(Html.Telerik().EditorFor(o => o.studentName).Encode(true)
                    .Tools(tools => tools.Clear().Bold().Italic().Underline().Separator().Strikethrough().FontName()
                        .FontSize(config => config.Add("inherited size", "8pt").Add("10 pixel", "10pt").Add("12 pixel", "12pt")
                                            .Add("14 pixel", "14pt").Add("18 pixel", "18pt").Add("24 pixel", "24pt"))
                        .FontColor().BackColor().JustifyRight()
                        .JustifyCenter().JustifyLeft().JustifyFull().InsertOrderedList().InsertUnorderedList()
                        .Indent().Outdent().FormatBlock())
                        .HtmlAttributes(new { @class = "HTMLEditorWidget" })
Controller: 
 [HttpPost]
 [ValidateInput(false)]
public ActionResult Index(StudentModel model)
{
if (some condition )
        {
ModelState.ModelState.AddModelError(String.Empty,"There is Some Errror");
 return View(model);
         }
else
{
return RedirectToAction("Index", "Home");
}
}

Model:
class StudentModel 

{
 [AllowHtml]
        [Display(Name = "CompanyProductName", ResourceType = typeof(PortalLocalization))]
        [StringLength(50,
"Student Name should not be greater than 50 charectors"]
        public string StudentName{ get; set; }
}
The problem is when I try to save the data and  if validation error Occurs the telerik editor shows me the text with HTML formatting( as shown in attached file).

2 Answers, 1 is accepted

Sort by
0
Jeff Trotman
Top achievements
Rank 1
answered on 23 Oct 2012, 05:33 PM
For what it's worth - I'm having basically the same problem.  I was getting it with the 2012Q2 code and just upgraded to the Q3 code and it didn't make a difference.

My model's property that's bound to the Editor definitely contains "un-encoded" HTML (have explicitly decoded what the editor sent to me on the Post) but when the Edit view displays after the validation error - it shows as encoded HTML. Initially (the first time the Edit view is rendered, before the initial post with the validation error) it displays the HTML properly.
0
Jeff Trotman
Top achievements
Rank 1
answered on 23 Oct 2012, 05:50 PM
Quick follow-up on this:
Originally, I wasn't setting the Encode property

@Html.Telerik().EditorFor(model => model.Body)

When I specifically set that property (see below) it started working.  That's not intuitive to me since it seems like it should have worked or not worked the same both times (initial view and after the validation error) but this seems to be working for me.

@Html.Telerik().EditorFor(model => model.Body).Encode(true)

Tags
Editor
Asked by
sushant
Top achievements
Rank 1
Answers by
Jeff Trotman
Top achievements
Rank 1
Share this question
or