views:

541

answers:

1

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?

+2  A: 

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);
Darin Dimitrov