Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoSave a form inputs using jQuery + ASP.NET MVC

We would like to implement a web form that automatically saves content at regular intervals.Something similar to gmail/google docs auto save funcationality.

Can some one suggest how to implement this using ASP.NET MVC + jQuery?

like image 382
Gopinath Avatar asked Jul 18 '09 11:07

Gopinath


1 Answers

jQuery Forms plugin and an ASP.NET MVC action should do the job:

public ActionResult SaveDraft(FormCollection form)
{
    // TODO: Save the form values and return a JSON result 
    // to indicate if the save went succesfully
    return Json(new { success = true });
}

And in your View just invoke this action periodically:

setInterval(function() {
    $('#theFormToSave').ajaxSubmit({ 
        url    : 'SaveDraft',
        success: function (data, textStatus) {
            if (data.success) {
                alert('form successfully saved');
            }
        }
    });
}, 30000);
like image 79
Darin Dimitrov Avatar answered Nov 08 '22 16:11

Darin Dimitrov