I've been playing around with the Editor control which is a great control however it seems to have a major bug\problem. When I edit my file in the editor it dosnt deal well with deletes.
I've a 3 line html (Sample.html) file like below.
<
p
>1 First line here.</
p
><
p
>2 Second line here.</
p
><
p
>3 Third line here.</
p
>
In the Editor I delete the second line and save the content and I expect to see:
<
p
>1 First line here.</
p
><
p
>3 Third line here.</
p
>
However what the editor actually creates is this:
<
p
>1 First line here.</
p
><
p
>3 Third line here.</
p
>><
p
>3 Third line here.</
p
>
Note the repeat of the line 3 and the </p>>
This is completely wrong! Am I doing something wrong?
The code for my view and my controller are as below:
View:
@
using
Mallon.Reporting.Artifacts
@
using
Mallon.Reporting.Extensions
@
using
DiamondFireWeb.Gui.Controllers
@
using
System.Collections.Generic
@
using
DiamondFireWeb.Gui.Extensions
@
using
TemplateEditorHelper
@
using
Kendo.Mvc.UI.Fluent
@model ModelEditorHtml
@{
ViewBag.Title =
"Editor Test "
;
bool
hideLayout = Convert.ToBoolean(ViewData[
"HideLayout"
]);
if
(hideLayout ==
null
|| hideLayout ==
false
)
{
Layout =
"~/Views/Shared/_Layout.cshtml"
;
}
string
imagesUrl = Url.GetRootUrl(
"/Content/TemplateImages/{0}"
);
}
@
using
(Html.BeginForm())
{
@Html.AntiForgeryToken()
<div>
@Html.HiddenFor(m => m.FilePath)
@(Html.Kendo().EditorFor(m => m.Content)
.Name(
"Content"
)
.HtmlAttributes(
new
{ style =
"width: 100%;height:440px"
})
.Tools(t =>
{
t.Clear();
t.Bold().Italic().Underline();
t.JustifyLeft().JustifyCenter().JustifyRight().JustifyFull();
t.InsertUnorderedList().InsertOrderedList();
t.Outdent().Indent();
t.InsertImage();
t.TableEditing();
t.Formatting();
t.CleanFormatting();
t.FontName();
t.FontSize();
t.FontColor().BackColor();
t.Print();
}
)
.Resizable(resizable => resizable.Content(
true
).Toolbar(
true
))
//.ImageBrowser(imageBrowser => imageBrowser
// .Image(imagesUrl)
// .Read("Read", "ImageBrowser")
// .Upload("Upload", "ImageBrowser")
// .Thumbnail("Thumbnail", "ImageBrowser"))
)
<input type=
"submit"
class
=
"k-button"
/>
</div>
}
Controller Methods:
public
ActionResult EditorTest()
{
ModelEditorHtml m =
new
ModelEditorHtml();
m.FilePath = @
"C:\Data\Sample.html"
;
m.Content = System.IO.File.ReadAllText(m.FilePath);
return
View(m);
}
[HttpPost]
[ActionName(
"EditorTest"
)]
public
ActionResult EditorTestSave(ModelEditorHtml m)
{
string
htmlValue = HttpUtility.HtmlDecode(m.Content);
using
(FileStream file =
new
FileStream(m.FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
using
(StreamWriter writer =
new
StreamWriter(file, Encoding.UTF8))
{
writer.Write(htmlValue);
}
}
return
RedirectToAction(
"EditorTest"
);
}
Model:
public
class
ModelEditorHtml
{
[AllowHtml]
public
string
Content {
get
;
set
; }
public
string
FilePath {
get
;
set
; }
}