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:
- var UserModel =
- {
- "id": id,
- "nombre_archivo": nombre_archivo
- };
- $.ajax({
- url: base_url(url_editar_grid),
- data: JSON.stringify(UserModel),
- type: 'POST',
- contentType: 'application/json; charset=utf-8',
- success: function (data) {
- $('#listGrid').trigger('reloadGrid');
- // alert(data);
- }
- });
- public JsonResult editar(periodo model)
- {
- var periodolista = new periodo();
- periodolista = periodolista.actualizarbatch(model.id, model.nombre_archivo);
- return Json(periodolista);
- }
- public periodo actualizarbatch(int varid, string varnombre)
- {
- var periodolista = new periodo();
- try
- {
- using (var ctx = new ProyectoContext())
- {
- periodolista = ctx.periodo.Where(x => x.id == varid).SingleOrDefault();
- if (!(periodolista == null))
- {
- periodolista.nombre_archivo = varnombre;
- }
- ctx.SaveChanges();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return periodolista;
- }
- ProyectoContext db = new ProyectoContext();
- [AcceptVerbs("Get", "Post")]
- public JsonResult GetTodoLists(JqGrid jqgrid, string sidx, string sord, int page, int rows) //Gets the todo Lists.
- {
- using (var ctx = new ProyectoContext())
- {
- ctx.Configuration.LazyLoadingEnabled = false;
- int pageIndex = Convert.ToInt32(page) - 1;
- int pageSize = rows;
- var todoListsResults = db.periodo.Select(a => new{a.id, a.añoId, a.trimestre,a.nombre_archivo,a.descripcion_archivo,a.fecha_creacion});
- int totalRecords = todoListsResults.Count();
- var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
- /*---*/
- if (sord.ToUpper() == "ASC")
- {
- todoListsResults = todoListsResults.OrderByDescending(s => s.id);
- todoListsResults = todoListsResults.Skip(pageIndex * pageSize).Take(pageSize);
- }
- else
- {
- todoListsResults = todoListsResults.OrderBy(s => s.id);
- todoListsResults = todoListsResults.Skip(pageIndex * pageSize).Take(pageSize);
- }
- /*---*/
- var jsonData = new
- {
- total = totalPages,
- page,
- records = totalRecords,
- rows = todoListsResults
- };
- return Json(jsonData, JsonRequestBehavior.AllowGet);
- }
- }
6 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Eli RaarPosted Jun 16, 2017, 1:01 PM
Eli RaarPosted Jun 16, 2017, 12:49 PM
Praveen KumarPosted Jun 16, 2017, 1:52 AM
Sundaram SubramanianPosted Jun 15, 2017, 10:47 PM
Nilesh ShahPosted Jun 15, 2017, 1:33 PM
Manikandan MurugesanPosted Jun 15, 2017, 1:21 PM