我有 Jquery 可排序 UI 我有 Web 服务来在用户更新提醒订单时更新提醒顺序 我知道将 json 数据传递给 Web 服务是有问题但无法解决
错误:无效的 Web 服务调用缺少值参数: System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext 上下文,WebServiceMethodData methodData,
System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary 2 参数)的 rlist2 parameters) at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
IDictionary`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>