0

我的网络服务方法如下:

 <WebMethod()> _
    Public Function TravelMeansList(ByVal prefix As String) As List(Of HRM_travellingMeans)
        Dim ctx As New HRMEntities
        Dim query = From c In ctx.HRM_travellingMeans Where c.name.ToUpper.StartsWith(prefix) Select c

        If query.Count > 0 Then
            Return query.ToList()
        Else
            Return Nothing
        End If

    End Function

我的脚本如下

<script type="text/javascript">
     $(document).ready(function () {

         $("#<%=travelmeansTextBox.ClientID %>").autocomplete({


             source: function (request, response) {
                 $.ajax({
                     url: '<%=ResolveUrl("../../services/ApplicationService.asmx/TravelMeansList") %>',
                     data: "{ 'prefix': '" + request.term + "'}",
                     dataType: "json",
                     type: "POST",
                     contentType: "application/json; charset=utf-8",
                     dataFilter: function (data) { return data; },
                     success: function (data) {
                         response($.map(data.d, function (item) {
                             return Json({

                                    value: item.name
                             })
                         }))
                     },
                     error: function (response) {
                         alert(response.responseText);
                     },
                     failure: function (response) {
                         alert(response.responseText);
                     }
                 });
             },
             select: function (e, i) {

             },
             minLength: 1
         });




     });
    </script>

我的问题是,每当我尝试在文本框中输入任何字母时,都会出现此错误

在 System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 深度、Hashtable objectsInUse、SerializationFormat serializationFormat、MemberInfo currentMember)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)\r\ n 在 System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer。SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable ......序列化枚举......序列化枚举......

我究竟做错了什么。

4

1 回答 1

1

问题可能在于实体框架对象的 JSON 序列化。参考这篇文章:

http://mytechworld.officeacuity.com/index.php/2010/02/serializing-entity-framework-objects-into-json-using-asp-net-mvc/

此处的作者建议您在使用 ASP.NET MVC 时使用 JSONResult 对象,但我不确定它与 jQuery Autocomplete 的效果如何。

于 2012-08-04T09:58:53.327 回答