$.ajax({ type: 'GET', url: '/Admin/SaveMyStuff', async: false, datatype: 'json', data: data, success: function (response) { if (response.length > 0) { alert(response); } else { alert('Data saved successfully'); ajaxReloadElement('/Admin/MyGrid', { id: getId() }, '#AdminGridDiv'); } } /* success*/ }); /* ajax */ . . . /*===========================================================================================*/ function ajaxReloadElement(url, data, targetSelector, httpMethod) { if (httpMethod == undefined || httpMethod == null) { httpMethod = 'GET'; } $.ajax({ type: httpMethod, url: url, async: false, datatype: 'json', data: data, success: function (response) { $(targetSelector).html(response); } /* success */ }); /* ajax */ }
public JsonResult SaveMyStuff(MyModel model) { if (!ModelState.IsValid) { var response = (from ms in ModelState.Values from err in ms.Errors select err.ErrorMessage).ToList().FirstOrDefault(); return Json(response, JsonRequestBehavior.AllowGet); } model.Save(); return Json("", JsonRequestBehavior.AllowGet); }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.