到目前为止,我已经被这个问题困扰了几个小时。
我试图通过删除或编辑jTable的一行记录来更新它,但每次我都会遇到相同的错误(即与服务器通信期间发生错误)。
我尝试了很多方法来解决这个问题,但到目前为止还没有成功。
我成功地添加了记录(即“教授”类的对象)。但编辑并未执行,相应对象(即教授) Controller 的 HTTPPost 启用方法也未执行。
我附上了屏幕截图。
另外,下面是 View 中的jTable代码。
<div id="ProfessorTableContainer"></div>
<script type="text/javascript">
$(document).ready(function ()
{
$('#ProfessorTableContainer').jtable({
title: 'Professor List',
paging: true,
pageSize: 10,
sorting: false,
actions:
{
listAction: '@Url.Action("GetProfessors")',
deleteAction: '@Url.Action("DeleteProfessor")',
updateAction: '@Url.Action("UpdateProfessor")',
createAction: '@Url.Action("CreateProfessor")'
},
fields: {
ProfessorId:
{
key: true,
create: false,
edit: false,
list: false
},
ProfessorName:
{
title: 'Name',
width: '23%'
}
}
});
$('#ProfessorTableContainer').jtable('load');
//Load all records when page is first shown
});
下面是Controller的Update方法或Delete方法的代码片段。
[HttpPost]
public JsonResult DeleteProfessor(int profId)
{
try
{
ProfRepository.DeleteProfessor(profId);
return Json(new { Result = "OK" });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
如果有人帮助我,我将非常感激。 我有点陷入困境,不知道如何解决这个问题。我已经看过所有的区域,一切看起来都足够完美和精致。
问候 乌斯曼
最佳答案
原因1:增删改查方法参数名称必须“record”
示例:公共(public)静态对象(产品记录)
原因 2:模型类必须无参数构造函数
示例:公共(public)产品(){}
关于jquery - J表: 'An error occured while communicating with the server ' while updating or deleting records,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20690069/