Search code examples
javascriptajaxwysiwygsummernote

What Should I Do To View The Formatted Data In WYSIWYG Editor?


I'm developing a web application using ASP.NET MVC. I want to submit the formatted text held in the MsSQL database to Summernote for editing. However, the JavaScript method I developed on the client side does not add only the post content from the server to the HTML document. I looked through the Insertion API in the Summernote documentation but couldn't find a solution.

The debug image below shows PostContent data coming from the database. The parts of the program I have developed are available below. What do I need to do to fix this problem?

Application Test Image

<div class="form-group">
    <label class="control-label">Content</label>
    <div id="summernote"></div>
</div>
function FUNCTION_GetPostDetailByPostID(e) {
    $.ajax({
        url: "/Post/GetPostDetailByPostID?postId=" + e,
        type: "get",
        success: function (e) {
            $("#inputPostID").val(e.ID);
            $("#inputTitle").val(e.Title);
            $("#inputSlug").val(e.Slug);
            $("#imgPost").attr("src", e.ImageUrl);
            $("#inputShortDescription").val(e.ShortDescription);
            $("#selectCategory").val(e.CategoryID);
            $("#inputDate")[0].value = e.ModifiedOnString;
            $("#inputIsActive")[0].checked = e.IsActive;

            /* The line below doesn't work, but there is no error warning in the console. */
            $("#summernote").code(e.PostContent);
        }
    });
}

Solution

  • You are probably using an updated version of Summernote. To print the formatted data from the database to the summernote container, update the $("#summernote").code(e.PostContent); line as follows:

    $("#summernote").summernote("code", e.PostContent);
    

    The sample application is available in the Basic API, not the Insertion API.