Use of older Telerik RTF/HTML editor

121 views Asked by At

My company has a license for one of the older Telerik packages. They would like me to place an RTF textbox in place of the normal Textbox on one of our screens. I have the extant code for the text box and I have another page used in our application which ostensibly works with the RTF editor (it's a part of functionality which is inaccessible to me at my privilege level). The original code was as follows:

@Html.TextAreaFor(m => m.LogEntry.Description, 
    new { @id = "logDescription", @class = "dirtyField", 
          style = "width: 400px; height: 100px;" })

The RTF code I'm patterning my code off of is as follows:

@(Html.Telerik().EditorFor(m => m.MessageContent)
    .Name("msgEditor")
    .HtmlAttributes(new { style = "width: 600px; height:250px; padding-top:0px; padding-bottom:0px;" })
    .Tools(tools => tools
    .Clear()
    .Bold().Italic().Underline().Strikethrough()
    .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
    .InsertUnorderedList().InsertOrderedList()
    .Outdent().Indent()
    .CreateLink().Unlink()
    .Subscript()
    .Superscript()
    .FontName()
    .FontSize()
    .FontColor().BackColor()
    )
)

I have the Editor control displaying, using our LogEntry.Description string instead of the above MessageContent. I can input text into it. I can load text into it. But when I try to save the entry off of a procedure called by a button in the dialog, the text of Description has been set to NULL. What am I doing wrong? I'm a newbie when it comes to web development, so I'm sort of grasping at straws.

I've looked at the answer at Telerik Editor doesn't work, but we have a ScriptRegistrar set up. The tutorials I can find on the Telerik site are all for the Kendo editor. This page seems more applicable, but, as far as I can tell, I'm doing all of the same things as they are. I tried to figure out if there was a place I needed to insert a call to HTMLEncode or HTMLDecode, but I've yet to find where the value is getting changed to NULL so as to catch it before then. Unfortunately, company code and all of that, I can only post so much of it, although I'll do my best to post sanitized specifics as necessary.

1

There are 1 answers

0
Sean Duggan On BEST ANSWER

For the sake of future people who have this issue, I hashed it out with one of the programmers here who had access to some additional code that had been published, but not added to our source code. I had to add code similar to the following inside the code run for the Javascript code associated with the Save button:

var editor = $("#descriptionEditor").data("tEditor");
var message = editor.value();

$("#logentry-encoded-message-content").val(message);

Within the CSHTML file, had to add the following element:

@Html.HiddenFor(m => m.LogEntry.EncodedDescription, new { @id = "logentry-encoded-message-content" })

Then, in the code involving processing the form, I assigned the contents of EncodedDescription to Description. Rather annoyingly, I have yet to find a way to just use one variable here. I did also have to add a modifier of [AllowHtml] to the EncodedDescription property to avoid the error message that there is potentially dangerous HTML being posted (since I know exactly what is being posted, and I know that it will be decoded and encoded for the control).