我收到以下错误:
"Message":"No parameterless constructor defined for type of \u0027System.String\u0027.","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.MissingMethodException"}
我假设发生这种情况是因为我没有正确地从我的 ajax 帖子中传递一些东西,但我看不到它:(。如果我没有传递任何参数,并且我从 web 方法中删除了参数,它就可以工作。但是,对于它们,它不会。此外,如果我尝试传递 JSON 对象,它也不起作用。我在底部发布了该代码。如果有人可以帮助我,我将不胜感激!谢谢。
AJAX
$.ajax({
type: "POST",
url: 'Process.aspx/updateAProcess',
data: JSON.stringify({ 'ProcessID': ProcessID, 'ProcessDescription': ProcessDescription, 'ProcessName': ProcessName }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
alert("Winner!");
}
});
网络方法
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function updateAProcess(ByVal ProcessID As String, ByVal ProcessDescription As String, ByVal ProcessName As String)
Dim pBSL As New ProcessBSL
pBSL.ProcessUpdate(ProcessID, ProcessDescription, ProcessName)
Return Nothing
End Function
使用 JSON
这是我的数据调用:
data: JSON.stringify({ updateProcess: updateProcess }),
这里是我创建 updateProcess 的地方:
var updateProcess = new Object();
updateProcess.ProcessName = $("#ProcessNameChange").val();
updateProcess.ProcessDescription = $("#ProcessDescChange").val();
updateProcess.ProcessID = $(this).closest("tr").children()[4];
它导致此错误:
{"Message":"Invalid web service call, missing value for parameter: \u0027ProcessID\u0027.","StackTrace"
在后端,我有一个名为 ProcessBO 的对象,它有十几个属性,我的 webmethod 是:
Public Shared Function update(ByVal updateProcess As ProcessBO)
Dim pBSL As New ProcessBSL
pBSL.ProcessUpdate(updateProcess.ProcessID, updateProcess.ProcessDescription, updateProcess.ProcessName)
Return Nothing