我已经将这个angularJs调用到了asmx WebMethod,但是我收到了有关转换的错误。这里代码为
AngulaJs致电:
$scope.delete = function (idNews) {
var url = '/data_db.asmx/SetDeleteNews';
var obj = idNews
$http.post(url,obj)
.success(
function (response) {
if (response.Error) {
console.log('Impossibile to remove.' + response.Message);
}
})
.error(
function (response) {
console.log('Error:' + response.ExceptionType);
console.log(response.Message);
console.log(response.StackTrace);
});
}
WebMethod,在C#中:
public bool SetDeleteNews(int i)
{
News n = new News
{
id = i,
title = string.Empty,
arg = string.Empty,
isDeleted = true,
};
bool result = BONewsLINQ.DeleteNews(n);
return result;
}
和BO:
public static bool DeleteNews(News delete)
{
using (Entity news = new Entity ())
{
try
{
News remove = news.News.Where(n => n.id == delete.id).FirstOrDefault();
news.News.Remove(remove);
news.SaveChanges();
return true;
} catch
{
return false;
}
}
}
错误是:
Error:System.InvalidOperationException
Cannot convert object of type 'System.Int32' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'
at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)
at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)
at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
我只传递一个int值(在var obj中),但是返回此错误。为什么?感谢