Eli Raar

Eli Raar

  • NA
  • 28
  • 1.6k

jqgrid no recarga uso mvc4 c#

Jun 15 2017 12:45 PM
Hello, I'm updating a table online, related one to many, this is my structure.

My interface, aki edito a row online, in this case, I click on "edit" and a fileupload appears, where I choose my file. Then press "burn", and if I update in the bd, but the grid does not update me and an error. It seems to me that when it is a single table if it works normal, but when the table is related it does not work and this error comes out:
 
 
This is my code for how you sent the data by ajax:
  1. var UserModel =  
  2.              {  
  3.                  "id": id,  
  4.                  "nombre_archivo": nombre_archivo  
  5.              };  
  6.          $.ajax({  
  7.              url: base_url(url_editar_grid),  
  8.              data: JSON.stringify(UserModel),  
  9.              type: 'POST',  
  10.              contentType: 'application/json; charset=utf-8',  
  11.              success: function (data) {  
  12.                  $('#listGrid').trigger('reloadGrid');  
  13.               //   alert(data);  
  14.              }  
  15.          });  
As receipt on controller:
  1. public JsonResult editar(periodo model)  
  2.         {  
  3.             var periodolista = new periodo();  
  4.             periodolista = periodolista.actualizarbatch(model.id, model.nombre_archivo);  
  5.              return Json(periodolista);  
  6.         }  
In the model:
  1. public periodo actualizarbatch(int varid, string varnombre)  
  2.       {  
  3.           var periodolista = new periodo();  
  4.           try  
  5.           {  
  6.               using (var ctx = new ProyectoContext())  
  7.               {  
  8.                       periodolista = ctx.periodo.Where(x => x.id == varid).SingleOrDefault();  
  9.   
  10.                       if (!(periodolista == null))  
  11.                       {  
  12.                           periodolista.nombre_archivo = varnombre;  
  13.                       }  
  14.                   ctx.SaveChanges();  
  15.   
  16.               }  
  17.   
  18.           }  
  19.           catch (Exception)  
  20.           {  
  21.   
  22.               throw;  
  23.           }  
  24.           return periodolista;  
  25.       }  
And as a weapon my jqgrid in the controller:
  1. ProyectoContext db = new ProyectoContext();  
  2.         [AcceptVerbs("Get""Post")]  
  3.         public JsonResult GetTodoLists(JqGrid jqgrid, string sidx, string sord, int page, int rows)  //Gets the todo Lists.  
  4.         {  
  5.             using (var ctx = new ProyectoContext())  
  6.             {  
  7.                 ctx.Configuration.LazyLoadingEnabled = false;  
  8.   
  9.                 int pageIndex = Convert.ToInt32(page) - 1;  
  10.                 int pageSize = rows;  
  11.                   var todoListsResults = db.periodo.Select(a => new{a.id, a.añoId, a.trimestre,a.nombre_archivo,a.descripcion_archivo,a.fecha_creacion});  
  12.   
  13.                 int totalRecords = todoListsResults.Count();  
  14.                 var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);  
  15.   
  16.                 /*---*/  
  17.   
  18.                 if (sord.ToUpper() == "ASC")  
  19.                 {  
  20.                     todoListsResults = todoListsResults.OrderByDescending(s => s.id);  
  21.                     todoListsResults = todoListsResults.Skip(pageIndex * pageSize).Take(pageSize);  
  22.                 }  
  23.                 else  
  24.                 {  
  25.                     todoListsResults = todoListsResults.OrderBy(s => s.id);  
  26.                     todoListsResults = todoListsResults.Skip(pageIndex * pageSize).Take(pageSize);  
  27.                 }  
  28.                 /*---*/  
  29.   
  30.                 var jsonData = new  
  31.                 {  
  32.                     total = totalPages,  
  33.                     page,  
  34.                     records = totalRecords,  
  35.                     rows = todoListsResults  
  36.                 };  
  37.                 return Json(jsonData, JsonRequestBehavior.AllowGet);  
  38.             }  
  39.         }  
Please answer some, I'm stuck on this, thanks.
 

Answers (6)