简体   繁体   中英

Removing block html tags. TinyMCE

I have added TinyMCE to my project. I have styled text and sent its value to database. Then I want it to be shown in the view. But it shown in HTML tags. How can I get rid of HTML tags?

Js:

  <script>
    tinymce.init({
        selector: '#Content',
        height: 500,
        theme: 'modern',
        plugins: [
            'advlist autolink lists link image charmap print preview hr anchor pagebreak',
            'searchreplace wordcount visualblocks visualchars code fullscreen',
            'insertdatetime media nonbreaking save table contextmenu directionality',
            'emoticons template paste textcolor colorpicker textpattern imagetools'
        ],
        forecolor: { inline: 'span', classes: 'forecolor', styles: { color: '%value' } },
        hilitecolor: { inline: 'span', classes: 'hilitecolor', styles: { backgroundColor: '%value' } },
        custom_format: { block: 'h1', attributes: { title: 'Header' }, styles: { color: 'red' } },
        toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
        toolbar2: 'print preview media | forecolor backcolor emoticons ',
        image_advtab: true,

    });
</script>

View:

   @foreach (Blog blog in Model.Blog)
      {
    @blog.posttext
                   }

posttext is shown like: <p><span style="color: #008080; background-color: #33cccc;">hi</span></p>

Finally, I solved it by disabling HTML encoding:

@Html.Raw(HttpUtility.HtmlDecode(blog.posttext))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM