Search code examples
jqueryajaxasp.net-mvc-4summernote

Can I use summernote html code to pass to jQuery ajax call


I'm trying to access value of summernote and try to pass it through ajax call but it is not calling the action of that controller.

log.cshtml

<div id="dvUpdate" class="tab-pane fade">
                        <form class="log-activity-form" id="addUpdate" name="addUpdate" novalidate>
                            <div class="wrapper wrapper-content animated fadeInRight">
                                <div class="row">
                                    <div class="col-sm-2">
                                        <label class="control-label">Update</label>
                                    </div>
                                    <div class="col-sm-10">
                                        <textarea rows="8" cols="150" class="summernote input-block-level" id="update" required></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-2">
                                        <label class="control-label">&nbsp;</label>
                                    </div>
                                    <div class="col-sm-10">
                                        <button class="btn btn-sm btn-primary pull-right" style="margin-top:10px;" type="submit"><strong>Save Update</strong></button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

javascript

 $('#update').summernote({
        focus: true,
        height: 500,
    });

    $("#addUpdate").submit(function () {            
        var textareaValue = $('#summernote').summernote('code');           

        var activityData = { distance: "", distancetype: "", hours: "", minutes: "", seconds: "", activity: "Update", activityName: "", date: moment.utc(), notes: textareaValue };

        $.ajax({
            type: "POST",
            contentType: 'application/json',
            url: "/Runner/CreateActivityLog",
            data: JSON.stringify(activityData),
            success: function (data) {
                //refresh feeds section                   
            }               
        });
        return false;
    });

I don't want to use razor syntax for form submit. I tried lots of combination to get the value of summernote, either it give object or null.

various ways i tried to get summernote code var textareaValue = $('#summernote').code(); var content = $('textarea[name="Update"]').html($('#summernote').code()); var data = $('#summernote').summernote('code');


Solution

  • for reading the values from summernote we have to use

    var textareaValue = $('#update').code();
    

    this will give us html data we entered in summernote.