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

[Solved] Showing HTML content on editor after HTTP POST

3 Answers 158 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.
Prashanth
Top achievements
Rank 1
Prashanth asked on 09 Jan 2012, 08:25 AM
hi,

I am facing an issue while using the editor on saving its contents.

we are using the editor in multiple views having the same model.so we tried to make the editor generic. for that we created a seperate static class EditorExtensions.cs  the code is as follows.

Code to make editor generic ( EditorExtensions.cs )
---------------------------
using Telerik.Web.Mvc.UI.Fluent;
using System.Web.Mvc;
using Investworks.Models;
namespace Telerik.Web.Mvc.UI
{
    public static class EditorExtensions
    {
        public static EditorBuilder Settings(this EditorBuilder editor, EditorProperties editorProperties)
        {
            if (!editorProperties.ShowTools)
            {
                editor.Tools(tools => tools.Clear());   
            }

            editor.HtmlAttributes(editorProperties.Attributes);

            return editor;
        }
    }


    public class EditorModel
    {
        public InvestworksDocumentRow DocumentModel
        {
            get;
            set;
        }

        public EditorProperties Properties
        {
            get;
            set;
        }
    }

    public class EditorProperties
    {
        public bool ShowTools
        {
            get;
            set;
        }

        public object Attributes
        {
            get;
            set;
        }

        public bool Encode
        {
            get;
            set;
        }

    }
}



here we are calling the partial view for editor: on the index .cshtm file
----------------------------------------------------------------------------------------

@{ Html.BeginForm(); }

@Html.Partial("~/Views/Shared/_Editor.cshtml", new EditorModel { DocumentModel = Model, Properties = new EditorProperties { ShowTools = true, Attributes = new { style = "height:200px" }, Encode = true} })

<p>
    <input type="reset" id="resetbButton" name="resetButton" value="Clear" onclick="clearEditor()" />
    <input type="submit" id="submitButton" name="submitButton" value="Save" />
</p>

@{ Html.EndForm(); }


Partal View  _Editor.cshtml
---------------------------------

@using Investworks.Models
@model  EditorModel    
        
    @{ Html.Telerik().Editor()           
           .Name("editor")
           
           .Settings(Model.Properties)
           .Value(@<text>          
           @Html.Raw(@Model.DocumentModel.idDocument.ConvertToString())
                </text>)               
    .Render();    } 

Controller for Editor
-------------------------

[ValidateInput(false)]
public ActionResult Index(string editor)
{
    if (editor != null)
    {
        ViewData["editor"] = editor;
        ViewData["value"] = HttpUtility.HtmlEncode(editor);
    }
    return View(dataProvider.uspSeltblId_InvestworksDocument("TX", "MB", null, null, null).FirstOrDefault());
}


[HttpPost]
[ValidateInput(false)]
public ActionResult Index(FormCollection form)
{
    string html = form["editor"];
    dataProvider.uspUpdInsMessageBoardText(html.ConvertToBytes());
    TempData["MessageBoardTextSavedMessage"] = "Message board text saved.";
    return RedirectToAction("Index", "MessageBoard");
}


here after posting the editor i am getting

form["editor"]= "\&lt;p&gt;\&amp;nbsp;Hallo \&lt;strong\&gt;Telerik\&lt;/strong\&gt;\&lt;/p\&gt;\&lt;p\&gt;\&lt;strong&gt;Please Help me\&lt;/strong\&gt;\&lt;/p\&gt;" (attached  image Editor2.jpg)

because of this it is showing the HTML string After saving the editor content.(attached image : Editor.jpg)

Please look into this issue and send me your response ASAP.

Thanks and Regards

Prashanth J Thomas


3 Answers, 1 is accepted

Sort by
0
Stephen
Top achievements
Rank 1
answered on 09 Jan 2012, 10:14 PM
I am having a similar issue to Prasanth, although my scenario is slightly simpler.

I have a view for creating forum posts.  It contains an editor control and some other controls, if validation fails I want the user to tidy up the validation issues before continuing.  Like Prasanth I am also using a HTTP post for this submission.  If the submission validation fails it will redirect the user back to the View.  The problem is that the contains all the HTML markup.  If the user keeps on clicking submit with the validation on the model still failing it will continue to pad out the markup with more markup!  This issue occurs with and without HttpUtility.DecodeHtml being called on the editor content.

In another view if the user wishes to edit said forum post, I just call HttpUtility.DecodeHtml and it works fine, unless of course some validation logic fails and the user is redirected back to the edit post view, which causes the issue described above.
0
Petur Subev
Telerik team
answered on 12 Jan 2012, 03:53 PM
Hi Prasanth,

To stop the cyclic encoding behavior you need to disable the encoding of the Editor because it is enabled by default.
i.e.
@(Html.Telerik().Editor()
        .Name("editor")
        .Encode(false)
)
I hope this helps.

Kind regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Stephen
Top achievements
Rank 1
answered on 23 Jan 2012, 03:16 AM
Thanks Petur, that worked for me.
Tags
Editor
Asked by
Prashanth
Top achievements
Rank 1
Answers by
Stephen
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or