我在 ASP.net 页面中遇到以下错误。我正在使用一个名为 jTable 的插件(引用 jTable.org)。此插件用于将 JSON 与 HTML UI 绑定(bind)。
我正在使用以下模型
[DataContract]
public class UserGroup
{
public UserGroup()
{
GroupId = 0;
}
#region Properties
public short GroupId { get; set; }
[DataMember]
public string GroupCode { get; set; }
[DataMember]
public char GroupType {get;set;}
[DataMember]
public string GroupDescription { get; set; }
#endregion
}
这是ASPX代码
<%@ Page Title="" AutoEventWireup="false" ViewStateMode="Disabled" Language="C#" MasterPageFile="~/Admin/Admin.Master" CodeBehind="Groups.aspx.cs"
Inherits="ERP.WebApp.Admin.Groups" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="../Content/themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<!-- jTable style file -->
<link href="/Scripts/jtable/themes/standard/blue/jtable_blue.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
<script src="/Scripts/jtablesite.js" type="text/javascript"></script>
<!-- A helper library for JSON serialization -->
<script type="text/javascript" src="/Scripts/jtable/external/json2.min.js"></script>
<!-- Core jTable script file -->
<script type="text/javascript" src="/Scripts/jtable/jquery.jtable.min.js"></script>
<!-- ASP.NET Web Forms extension for jTable -->
<script type="text/javascript" src="/Scripts/jtable/extensions/jquery.jtable.aspnetpagemethods.min.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<br /><br />
<div style="width:70%;margin:auto;height:500px">
<div id="GroupTableContainer"></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
//Prepare jtable plugin
$('#GroupTableContainer').jtable({
title: 'List of User Groups',
paging: true, //Enables paging
pageSize: 10, //Actually this is not needed since default value is 10.
sorting: true, //Enables sorting
defaultSorting: 'GroupCode ASC', //Optional. Default sorting on first load.
actions: {
listAction: '/Admin/Groups.aspx/GroupsList',
createAction: '/Admin/Groups.aspx/CreateGroup',
updateAction: '/Admin/Groups.aspx/UpdateGroup',
deleteAction: '/Admin/Groups.aspx/DeleteGroup'
},
fields: {
GroupId: {
key: true,
create: false,
edit: false,
list: false
},
GroupCode: {
title: 'Group Code',
width: '15%'
},
GroupType: {
title: 'Group Type',
width: '25%',
options: { 'S': 'Student', 'F': 'Faculty', 'A': 'Accounts', 'M': 'Management', 'B': 'Library Staff', 'L': 'Lab Staff', 'E': 'E.R.P. Admins','T':'Training & Placement' }
},
GroupDescription: {
title: 'About the Group',
type: 'textarea',
width: '50%'
}
}
});
//Load Groups list from server
$('#GroupTableContainer').jtable('load');
});
</script>
<br /><br />
</asp:Content>
这是我正在使用的 ASPx.cs 代码
[WebMethod(EnableSession = true)]
public static object GroupsList(int jtStartIndex = 0, int jtPageSize = 10, string jtSorting = null)
{
try
{
short pTotalRows = 0;
List<UserGroup> groupList = new GroupsBL().GetAllUserGroups(out pTotalRows,(short)jtStartIndex,(byte) jtPageSize, jtSorting);
//Return result to jTable
return new { Result = "OK", Records = groupList, TotalRecordCount = pTotalRows };
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
[WebMethod(EnableSession = true)]
public static object CreateGroup(UserGroup pUserGroup)
{
try
{
var addedStudent = new GroupsBL().AddUserGroup(pUserGroup);
if (addedStudent == true)
return new { Result = "OK"};
else
return new { Result = "ERROR", Message = "Group Already Exists" };
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
[WebMethod(EnableSession = true)]
public static object UpdateGroup(UserGroup pUserGroup)
{
try
{
var updatedstudent = new GroupsBL().UpdateUserGroup(pUserGroup);
if (updatedstudent == true)
return new { result = "ok"};
else
return new { Result = "ERROR", Message = "Group Already Exists" };
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
[WebMethod(EnableSession = true)]
public static object DeleteGroup(int pGroupId)
{
try
{
var deletedStudent = new GroupsBL().DeleteUserGroup((short)pGroupId);
if(deletedStudent == true)
return new { Result = "OK" };
else
return new { Result = "ERROR" };
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
带分页的选择操作工作正常,而任何其他操作(如更新、删除、创建)都会导致相同的错误。在上面或下面的屏幕截图中通过 Firebug 插件显示。
{“消息”:“无效的 Web 服务调用,缺少参数值:\u0027pUserGroup\u0027。”,“StackTrace”:“在 System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标, IDictionary 2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2 个参数)\r\n 在 System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n 在 System.Web.Script.Services.RestHandler。 ExecuteWebServiceCall(HttpContext 上下文,WebServiceMethodData 方法数据)","ExceptionType":"System.InvalidOperationException"
最佳答案
我发现了错误, 例如更新方法 我写的函数如下
public static object UpdateGroup(UserGroup pUserGroup)
根据 jTable 插件的创建者,它应该如下所示
public static object UpdateGroup(UserGroup record)//他在某处硬编码了参数名称
。
关于c# - ASP.net 应用程序中 JTable 的更新、删除、编辑操作出错,而选择工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8912639/