I'm having a problem after server side validation fails and the model is returned to the editor.
Here is the code for the model field that needs to be edited using the kendo editor:
At the moment the HelpText filed has the following data in the database:
When the page is initially displayed the text above is rendered in the kendo editor as expected (with styles instead of html tags - see goodeditor image). Inspecting Model.HelpContent within the razor code shows that the field contains the above code.
When the form is submitted with the above content, the content is encoded so that it looks like:
<p>Bacon ipsum dolor sit amet shoulder tenderloin corned beef, hamburger chicken ham hock strip steak.</p>
The ActionResult that is handling the post:
Inspecting the repositoryHelpEditModel.HelpContent field shows the encoded content, which is under 120 characters so it is decoded and saved to the database.
However, when the text is updated so that there are more than 120 characters and then the form submitted, the validation fails (since the length of repositoryHelpEditModel.HelpContent is > 120). For example if I add the text "More text." to the editor and submit then the value of repositoryHelpEditModel.HelpContent will be:
<p>Bacon ipsum dolor sit amet shoulder tenderloin corned beef, hamburger chicken ham hock strip steak. More text.<br /></p>
Since the validation fails, HelpContent is decoded again and the model is returned to the view to be displayed in the editor.
This time the text is rendered with html tags (see badeditor image) instead of showing marked up content.
Here is the code for the editor:
Is this a bug with the editor or am I doing something wrong here?
Here is the code for the model field that needs to be edited using the kendo editor:
[Required]
[MaxLength(120, ErrorMessage = "You must enter less than 120 characters.")]
public string HelpContent { get; set; }
<
p
>Bacon ipsum dolor sit amet shoulder tenderloin corned beef, hamburger chicken ham hock strip steak.</
p
>
When the form is submitted with the above content, the content is encoded so that it looks like:
<p>Bacon ipsum dolor sit amet shoulder tenderloin corned beef, hamburger chicken ham hock strip steak.</p>
The ActionResult that is handling the post:
public ActionResult EditRepositoryHelp(RepositoryHelpEditModel repositoryHelpEditModel)
{
if (ModelState.IsValid)
{
repositoryHelpEditModel.HelpContent = HttpUtility.HtmlDecode(repositoryHelpEditModel.HelpContent);
Repository.UpdateRepositoryHelpText(repositoryHelpEditModel);
return RedirectToAction("Index", "Admin");
}
repositoryHelpEditModel.HelpContent = HttpUtility.HtmlDecode(repositoryHelpEditModel.HelpContent);
return View(repositoryHelpEditModel);
}
However, when the text is updated so that there are more than 120 characters and then the form submitted, the validation fails (since the length of repositoryHelpEditModel.HelpContent is > 120). For example if I add the text "More text." to the editor and submit then the value of repositoryHelpEditModel.HelpContent will be:
<p>Bacon ipsum dolor sit amet shoulder tenderloin corned beef, hamburger chicken ham hock strip steak. More text.<br /></p>
Since the validation fails, HelpContent is decoded again and the model is returned to the view to be displayed in the editor.
This time the text is rendered with html tags (see badeditor image) instead of showing marked up content.
Here is the code for the editor:
@( Html.Kendo().EditorFor(model => model.HelpContent)
.Encode(true)
.HtmlAttributes(new { style = "width:100%;height:440px" })
.Tools(tools => tools.Clear()
.Bold().Italic().Underline().FontSize().FontColor().JustifyLeft()
.JustifyCenter().JustifyRight().JustifyFull().InsertUnorderedList()
.InsertOrderedList().Indent().CreateLink().ViewHtml()))
Is this a bug with the editor or am I doing something wrong here?