when I create a area I use JQuery to call the action create the action save to the db and return jsaon now when is save i want to be rendered to my index view how can i do that?? whith my code i have is that posible? i tried to call to the action index with jquery it call fine to the action but not render to the view index
[HttpPost]
public ActionResult Create(int? id,string nombre, int idDpto )
{
try
{
if (id != null)
{
Area c = (from x in db.Areas
where x.AreaId == id
select x).First();
c.NombreArea = nombre;
c.DepartamentoId = idDpto;
db.SaveChanges();
return Json(new { ok = true, message = "saved employee " });
}
Area e = new Area()
{
NombreArea = nombre,
DepartamentoId = idDpto
};
db.Areas.Add(e);
db.SaveChanges();
return Json(new { ok = true, message = "saved employee " });//+ emp.NameEmployee
}
catch (Exception ex)
{
return Json(new { ok = false, message = ex.Message });
}
}
function saveEmployee() {
var urlSave = '@Url.Action("Create")';
var iddpt = $("#cmbDept").val();
var name = $("#txtemp").val();
var idArea = $("#AreaId").val();
if (!name) {
window.alert('el nombre y el departamento son requeridos');
}
else {
if (! iddpt) {
window.alert('el departamento es requerido');
}
else {
$.ajax({
type: "POST",
url: urlSave,
data: { id: idArea, nombre: name, idDpto: iddpt },
success: function (returndata) {
if (returndata.ok) {
window.alert(' Guardado ');
}
else {
window.alert(' error : ' + returndata.message);
}
}
}
);
}
}
}