error de archivo jquery al cargar jtable en la aplicación MVC 4 ASP.net
Frecuentes
Visto 1,131 veces
1
Estoy desarrollando una aplicación web en asp.net MVC 4. Estoy llenando una jtable con datos JSON.
Pero me sale error"
No se puede llamar al método 'datos' de Undefined jtable/jquery.jtable.js:436
" He estado buscando la solución de este error, pero no puedo resolverlo. También soy un novato en MVC y jQuery. Así que comparto mi código a continuación para el controlador y veo ambos. Y he depurado y verificado mientras mi base de datos devolver el problema de datos es mientras se carga el jtable
Ver código de archivo para cargar jtable
@{
ViewBag.Title = "Patients";
}
<div id="StudentTableContainer1">
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#StudentTableContainer1').jtable({
title: 'Patients List',
actions: {
listAction: ' @Url.Action("PatientsList")',
deleteAction: '@Url.Action("DeleteStudent")',
updateAction: '@Url.Action("UpdateStudent")',
createAction: '@Url.Action("CreateStudent")'
},
fields: {
PatientId: {
key: true,
create: false,
edit: false,
list: false
},
MedicalRegNo: {
title: 'MedicalRegNo',
width: '23%'
},
OldMedicalRegNo: {
title: 'OldMedicalNo',
width: '23%'
},
FirstName: {
title: 'FirstName',
width:'12%'
},
Gender:{
title: 'Gender',
width:'13%'
},
DOB: {
title: 'DOB',
width:'13%'
},
CNIC: {
title: 'CNIC',
width:'11%'
}
}
});
//Load student list from server
$('#StudentTableContainer1').jtable('load');
});
</script>
Código del controlador
[HttpPost]
public JsonResult PatientsList()
{
try
{
Thread.Sleep(200);
var Patients = obj_class.GetPatients();
return Json(new {Result = "OK", Records = Patients});
}
catch (Exception ex)
{
return Json(new {Result = "ERROR", Message = ex.Message});
}
}
1 Respuestas
0
En realidad, lo resolví, el error era que las columnas que estaba usando para mostrar en jtable eran diferentes, deberían tener que ser las mismas que el objeto del método JSonResult que vuelve a ver.
Como quiero dar un ejemplo para esto:
tengo una jtable:
<div id="Mytable"></div>
$(document).ready(fucntion(){
$('#Mytable').jTable{
title:'My Jtable',
actions:
{
listAction:'@url.Action("MytableData")'
},
fields:{
ID:{
title:'ID',
widthL'20%'
},
Name:{
title:'My name',
width:'20%'
}
}
});
$('#Mytable').jTable.('load')
});
Y mi controlador que devuelve el objeto JSON para MytableData es:
using System.Web.Mvc;
using System.Web.SessionState;
using System.Linq;
namespace CrudPlugInDevelop.Controllers
{
public class DemoController : RepositoryBasedController
{
PatientsModel obj_data=new PatientsModel();
public JsonResult MyTableData(string name)
{
List<DB_Patient> obj_data = context.PatientsList(name);
return Json(new { Result = "OK", Records = obj_data });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
}
Y mi clase modelo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using mEMR.Core.Interfaces;
namespace mEMR.Core.Models.PatientSearch
{
public class PatientSearchViewModel : IPatientSearchModel
{
public int ID { get; set; }
[DisplayName("First Name")]
public string Name { get; set; }
Entonces, aquí tiene, si en el modelo tiene una columna de nombre en la columna jtable, debería ser el nombre si lo cambia por nombre o cualquier otra cosa, no mostrará los datos en jtable. Me lo imaginé.
Respondido el 08 de diciembre de 13 a las 15:12
ya lo veo venir. porque me encontré con lo mismo - Vivej
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas asp.net-mvc-4 visual-studio-2012 jquery-jtable or haz tu propia pregunta.
estaba mostrando jtable en su navegador. como Jtable vacío - Vivekh
Lo siento, olvidé responder esta pregunta yo mismo porque resolví el problema. - jahanzaib kk