This question is locked. New answers and comments are not allowed.
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"]= "\<p>\&nbsp;Hallo \<strong\>Telerik\</strong\>\</p\>\<p\>\<strong>Please Help me\</strong\>\</p\>" (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
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"]= "\<p>\&nbsp;Hallo \<strong\>Telerik\</strong\>\</p\>\<p\>\<strong>Please Help me\</strong\>\</p\>" (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