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

[Solved] Editor ignore specified value if value found in model

2 Answers 126 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.
Sam Critchley
Top achievements
Rank 1
Sam Critchley asked on 23 Sep 2010, 07:11 AM
This line here in EditorHtmlBuilder:

var value = editor.ViewContext.ViewData.Eval(editor.Name) ?? editor.Value;

is annoying me severely. I'm trying to Decode the value before its output because something somewhere (possibly the model binder) is encoding it on it's way to the database. One it's way back it's appearing in the editor as escaped html.

So I changed my editor template to do this (with HtmlDecode call)

Html.Telerik().Editor().Name(ViewData.TemplateInfo.GetFullHtmlFieldName("")).Tools((p) =>
    {
        p.Clear();
        p.FormatBlock().Bold().Italic().Underline().Strikethrough().JustifyLeft().JustifyCenter().JustifyRight().JustifyFull().InsertOrderedList().InsertUnorderedList().Indent().Outdent().CreateLink().Unlink().InsertImage();
    }).Value(Server.HtmlDecode(Convert.ToString(Model))).Render();

Only to discover it's ignoring what's passed in. MS likes doing this sort of thing too. If I specify a value I won't the component to use that value. Reading stuff from the ViewData should be the fallback not the other way around!

This line should be:

var value = editor.Value ?? editor.ViewContext.ViewData.Eval(editor.Name);

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Sep 2010, 07:23 AM
Hi Sam Critchley,

 I think this is the expected behavior. At least the built-in TextBox extension behaves in that way. I have attached a sample project. If you type in the textbox and then post - the new content will appear not the one set in the view.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sam Critchley
Top achievements
Rank 1
answered on 23 Sep 2010, 08:01 AM
I'm sure it is by design. I'm questioning the design :)

As Telerik editor sends the data html encoded to the server I have to at some point call Decode on it otherwise it's just continually encoded over and over everytime it's edited. It creates work, pretty much for every case it's used... and I don't like work.

I've had to add this to my automapper mappings, one for addmodel to entity and one for editmode to entity.

.ForMember(p=>p.Content, p=>p.MapFrom(x=>System.Web.HttpUtility.HtmlDecode(x.Content)))
Tags
Editor
Asked by
Sam Critchley
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Sam Critchley
Top achievements
Rank 1
Share this question
or