I have a project that is bilingual and I have a story for each language. I want to use TinyMCE to get formatted Html Text and also set those Textareas from the database.
This is my model for blogs:
Model:
[Required(ErrorMessage = "Please add the news context")]
[MinLength(10, ErrorMessage = "The length of news context must be 10 characters atleast")]
[Display(Name = "News Context")]
[UIHint("tinymce_jguery_full"), AllowHtml]
public string newsContent { get; set; }
[Required(ErrorMessage = "شرح خبر نمی تواند خالی باشد")]
[MinLength(10, ErrorMessage = "حداقل طول شرح خبر 10 حرف است")]
[Display(Name = "شرح خبر")]
[UIHint("tinymce_jguery_full"), AllowHtml]
public string newsContentFa { get; set; }
I can also successfully fetch that blog with a service.Get_Category_List() method as follow code in NewsmanagementControler
Controller:
public ActionResult Edit(int id)
{
using (DbModel db = new DbModel())
{
News SelectedNews = new News();
var news = service.GetNews_ById(id);
return View(news);
}
}
And finally in the View I set tinyMCE from the raw Html fetched from database as following code:
View
<script src='//cdn.tinymce.com/4/tinymce.min.js'></script>
<script type="text/javascript">
tinymce.init({
selector: 'textarea',
mode: "textareas",
theme: 'modern',
entity_encoding: 'raw',
height: 300,
plugins: [
'advlist autolink link lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime nonbreaking',
'save table colorpicker contextmenu directionality paste textcolor image'
],
content_css: '../../Content/css/tinyMCE.css',
toolbar: 'insertfile undo redo | styleselect | fontselect | sizeselect | fontsizeselect bold italic underline | alignleft aligncenter alignright alignjustify | ltr rtl | bullist numlist outdent indent | link | print preview fullpage | forecolor backcolor image',
fontsize_formats: "8pt 10pt 12pt 14pt 16pt 18pt 20pt 24pt 36pt",
font_formats: "Arial=arial,helvetica,sans-serif;" +
"Arial Black=arial black,avant garde;" +
"B Yekan=BYekan" +
"Courier New=courier_newregular,courier;" +
"Impact=impactregular,chicago;" +
"Tahoma=tahoma,arial,helvetica,sans-serif;" +
"Times New Roman=times new roman,times;" +
"Verdana=verdana,geneva;" +
"Webdings=webdings;" +
"Wingdings=wingdings,zapf dingbats",
draggable_modal: true
});
</script>
@using (Html.BeginForm("Edit", "NewsManagement", FormMethod.Post))
{
<div class="col-md-12 ltr">
<br />
<label for="MainContent">Context of Blog</label>
@Html.TextAreaFor(m => m.news.newsContent, new { @class = "fullWidth tiny", placeholder = "Main Content" })
@Html.ValidationMessageFor(m => m.news.newsContent, "", new { @class = "redError" })<br />
<br />
</div>
<div class="col-md-12 rtl">
<br />
<label for="MainContentFa">شرح مطلب</label>
@Html.TextAreaFor(m => m.news.newsContentFa, new { @class = "fullWidth tiny rtl", placeholder = "شرح مطلب" })
@Html.ValidationMessageFor(m => m.news.newsContentFa, "", new { @class = "redError" })<br />
</div>
}
I don't have any problem with save raw Html tinyMCE but for showing my stored raw html in database, there is a problem - as seen in this screenshot:
As you can see the raw HTML doesn't render in TinyMCE. I searching everywhere on google and here too, but there isn't any right answer according to my problem.
