Hello, you should try this code to autosave
HTML Code:
< div >
@Html.HiddenFor(model = > model.MyNoteViewModels.ICTMyNoteId, new {@id = "ID"})
@Html.TextAreaFor(model = > model.NoteViewModels.NoteItemText, new {@id = "Text", @onkeyup = "autosave()"})
< /div>
<script>
var autosave_timer = null;
function save() {
$.ajax({
type: "POST",
url: '@Url.Action("SaveNotes", "Note")',
data: { nID: $('#ID').val() || 0, nText: $('#Text').val() },
success: function (data) {
console.log("Notes saved");
}
})
}
function autosave() {
if (autosave_timer)
clearTimeout(autosave_timer);
autosave_timer = setTimeout(save, 5000);
}
</script >
HTML Code:
public ActionResult SaveNotes(int nID, string nText)
{
MyNoteViewModel model = new MyNoteViewModel();
model.Id = nID;
model.Text = nText;
bool results = false;
results = _myNMgr.SaveNoteText(model);
return View(model);
}
If you have any query you can check these resources
c-sharpcorner