Grayson Mitchell
Grayson Mitchell

Reputation: 1187

asp.net mvc how to save data from jquery control

I am using the TinyMCE control in a MVC page, and now I want to save the content of the control (hopefully with ajax so the page is not rendered again)... I have some javascript that looks like this:

 mysave = function() {
    var ed = tinyMCE.get('content');
    // Do you ajax call here, window.setTimeout fakes ajax call

    ed.setProgressState(1); // Show progress  

    window.setTimeout(function() {
        ed.setProgressState(0); // Hide progress
        alert(ed.getContent());
    }, 3000);
};

What is the best way to pass the content back to the controller, save it, and return back to the same page?

Upvotes: 1

Views: 1808

Answers (1)

Ilya Khaprov
Ilya Khaprov

Reputation: 2524

well, use jQuery.ajax. http://docs.jquery.com/Ajax. I suggest you to use POST request so you can transfer arbitrary long texts.

How do you plan to save the text? Do you use any database engine? we need more information.

$.ajax({
    url: "/controller/savetext",
    cache: false,
    type: "POST",
    data: { text: ed.getContent() },
    success: function(msg) {
        alert("text saved!");
    },
    error: function(request, status, error) {
        alert("an error occurred: " + error);
    }
})

and on server side something like this:

string text = Request.Form["text"]

Upvotes: 3

Related Questions