我有Jquery可排序的UI我有Web服务来更新提醒顺序当用户更新提醒命令时我知道将json数据传递给Web服务但是无法解决它的问题
错误:
无效的Web服务调用缺失值参数:rlist 在System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target,IDictionary2 parameters) at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2个参数) 在System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context,WebServiceMethodData methodData,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>
答案 0 :(得分:0)
尝试按预期发送Id
和Order
整数。
var reminderObject = {
Id: parseInt($(this).attr("id"), 10),
Order: parseInt($(this).find("input[type='hidden']").val(), 10)
};
同时将wrap.d = orderArray
更改为wrap.rList = orderArray
,因为rList
是预期参数。