Ошибка при обновлении, удалении, операции редактирования в JTable в приложении ASP.net, в то время как выбор работает отлично - PullRequest
1 голос
/ 18 января 2012

У меня следующие ошибки на странице ASP.net. Я использую плагин под названием jTable (Ссылка jTable.org). Этот плагин используется для привязки JSON к пользовательскому интерфейсу HTML.

enter image description here

Я использую следующую модель

[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 на скриншоте выше или следующим образом.

{"Сообщение": "Недопустимый вызов веб-службы, отсутствует значение параметра: \ u0027pUserGroup \ u0027.", "StackTrace": "at 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, метод WebServiceMethodData, IDictionary`2 rawParams) \ r \ n в System.Web.Script.Services.RestHandler. ExecuteWebServiceCall (контекст HttpContext, метод WebServiceMethodData methodData) "," ExceptionType ":" System.InvalidOperationException "}

1 Ответ

4 голосов
/ 18 января 2012

Я нашел ошибку, ex в случае метода обновления функция, которую я написал, выглядит следующим образом

 public static object UpdateGroup(UserGroup pUserGroup)

в то время как согласно создателю плагина jTable это должно быть следующим

public static object UpdateGroup(UserGroup record)// he hardcoded parameter name at somewhere.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...