0

我有 Jquery 可排序 UI 我有 Web 服务来在用户更新提醒订单时更新提醒顺序 我知道将 json 数据传递给 Web 服务是有问题但无法解决

错误:无效的 Web 服务调用缺少值参数: System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext 上下文,WebServiceMethodData methodData,
System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary 2 参数)的 rlist 2 parameters) at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionaryIDictionary`2 rawParams) 在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)

 Web Services 
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using Compudata_ProjectManager.CodeFile.BOL;
    using System.Data.SqlClient;
    using System.Web.Script.Services;

    namespace Compudata_ProjectManager.WebServices
    {
        /// <summary>
        /// Summary description for remindersWebService
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
         [ScriptService]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class remindersWebService : System.Web.Services.WebService
        {


            public class ReminderDTO
            {
                public int Id { get; set; }
                public int Order { get; set; }
            }

            [WebMethod]
            [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
            public string UpdateOrder(List<ReminderDTO> rList)
            {
                //CompuData_ProjectManagerConfiguration.DbconnctionString;

                using (SqlConnection connectionString = new SqlConnection(CompuData_ProjectManagerConfiguration.DbconnctionString))
                {

                    foreach (var r in rList)
                    {
                        string sSQL = "UPDATE [TaskManagementSystem_DB].[dbo].[Reminders] SET [reminderOrder] = " +  r.Order.ToString() + "where reminderID = " + r.Id;

                        SqlCommand cmd = new SqlCommand(sSQL, connectionString);

                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                            return "falied";
                        }


                    }
                    return "save";
                }
            }
        }
    }

javascript 

    $(function () {
        $("#sortable").sortable({
            placeholder: "vacant",
            update: function (e, ui) {
                //process each li

                //create vars
                var orderArray = [];
                var wrap = {};
                $("#sortable li").each(function () {


                    //build ReminderObject
                    var reminderObject = {
                        Id: $(this).attr("id"),
                        Order: $(this).find("input[type='hidden']").val()
                    };

                    //add object to array 
                    orderArray.push(reminderObject);

                });

                wrap.d = orderArray


                //pass to server 
                $.ajax({
                    type: "POST",
                    url: "../WebServices/remindersWebService.asmx/UpdateOrder",
                    data: JSON.stringify(wrap),
                    processData: false,
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        if (data.d === "saved") {
                            document.write("Save ok");
                        } else {
                            document.write("Save failed");
                        }
                    },
                    error: function (xhr, status, error) {
                        var err = eval("(" + xhr.responseText + ")");
                        console.log(err.StackTrace);
                        alert(err.Message);
                    }
                });

            } //end of update function 
        });
        $("#sortable").disableSelection();



        $("input[type=checkbox]").on("click", function () {
            $(this).nextAll().toggleClass("hidden");
        });

    });

</script>
4

1 回答 1

0

尝试发送IdOrder作为预期的整数。

var reminderObject = {
    Id: parseInt($(this).attr("id"), 10),
    Order: parseInt($(this).find("input[type='hidden']").val(), 10)
};

也更改wrap.d = orderArraywrap.rList = orderArrayasrList是预期的参数。

于 2013-03-04T16:01:22.170 回答