private static void SendResponse(HttpResponse response, DataTableResultSet result) { response.Clear(); response.Headers.Add("X-Content-Type-Options", "nosniff"); response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); response.ContentType = "application/json; charset=utf-8"; response.Write(result.ToJSON()); response.Flush(); response.End(); }
public ActionResult IndexAjax(object data) { try { var req = DataTableParameters.Get(data); var resultSet = new DataTableResultSet(); int _Start = req.Start; int _Length = req.Length; string _SearchValue = req.SearchValue; int _OrderBy = -1; string _OrderDirection = string.Empty; int _TipoBusqueda = -1; if (req.Order.Count > 0) { foreach (var aux in req.Order.Keys) { _OrderBy = req.Order[aux].Column; _OrderDirection = req.Order[aux].Direction; } } foreach (var busq in req.Columns.Keys) { if (!string.IsNullOrEmpty(req.Columns[busq].SearchValue)) { _TipoBusqueda = busq; _SearchValue = req.Columns[busq].SearchValue; break; } } _CompraAlmacen_Datos Datos = new _CompraAlmacen_Datos(); CompraAlmacenModels Resultado = Datos.ObtenerGridComprasAJAX(Conexion, _Start, _Length, _SearchValue, _OrderBy, _OrderDirection); resultSet.draw = req.Draw; resultSet.recordsTotal = Resultado.TotalRecords; resultSet.recordsFiltered = Resultado.SearchRecords; foreach (CompraAlmacenModels Item in Resultado.Lista) { var columns = new List <string>(); columns.Add(Item.Sucursal.NombreSucursal); columns.Add(Item.NumFacturaNota); columns.Add(Item.Proveedor.nombreProveedor); string estatus = string.Empty; switch (Item.IDEstatusCompra) { case 1: estatus = @"<td><span class='label label-warning'>" + Item.StatusCompra + @"</span></td>"; break; case 2: estatus = @"<td><span class='label label-primary'>" + Item.StatusCompra + @"</span></td>"; break; case 3: estatus = @"<td><span class='label label-success'>" + Item.StatusCompra + @"</span></td>"; break; } columns.Add(estatus); string acciones = @""; columns.Add(acciones); resultSet.data.Add(columns); } return(Json(resultSet.ToJSON())); } catch (Exception ex) { TempData["typemessage"] = "2"; TempData["message"] = "No se pudo borrar los datos. Por favor contacte a soporte técnico"; return(Json("")); } }