2012-09-16 57 views
0

这个jQuery呼叫保持与以下错误messeage失败:"Cannot convert object of type 'System.String' to type 'System.Collections.Generic.IDictionary 2 [System.String,System.Object的]'“`将数据传递到从jQuery的asp.net页面方法失败

jQuery的:

$('input, select').blur(function() 
       { 
        var categoryId = $('#IncidentCategoryEnhancedDropDownList').val(); 
        var latitude = $('#LatitudeHidden').val(); 
        var longitude = $('#LongitudeHidden').val(); 
        var dateTime = $('#DateEnhancedTextBox').val(); 

        if (categoryId == '--Select--') 
        { 
         return; 
        } 

        if (!latitude.length || !longitude.length) 
        { 
         return; 
        } 

        if (!dateTime.length) 
        { 
         return; 
        } 

        $.ajax({ 
         type: "POST", 
         url: "ReportIncident.aspx/GetIncidentsNearBy", 
         data: $.toJSON('{categoryId:"' + categoryId + '",latitude:' + latitude + ',longitude:' + longitude + ',dateTime:"' + dateTime + '"}'), 
         contentType: "application/json; charset=utf-8", 
         dataType: "json", 
         success: function (msg) 
         { 
          console.log(msg.d); 
          // $("#Result").text(msg.d); 
         } 

        }); 
       }); 

页方法:

[WebMethod] 
     public static IList<IncidentDTO> GetIncidentsNearBy(int categoryId, float latitude, float longitude, DateTime dateTime) 
     { 
      var incidents = new MendixIncidentDAO().GetIncidents() 
       .Where(i => i.IncidentTypeId == categoryId) 
       .Where(i => i.Date >= dateTime.AddHours(-1) && i.Date <= dateTime.AddHours(1)) 
       .Where(
        i => 
        SpatialHelpers.DistanceBetweenPlaces((double) longitude, (double) latitude, (double) i.Longitude, 
                 (double) i.Latitude) < 1) 
       .Select(
        i => 
        new IncidentDTO 
         { 
          Id = i.IncidentId, 
          IncidentCategory = i.IncidentType, 
          Address = i.Address, 
          FormattedDate = i.FormattedDate 
         }); 
      return incidents.ToList(); 
     } 
+1

您的服务器端代码失败。只需调试C#代码并查看出了什么问题。 –

+0

@Alexei我收到'No source available ...'和完全相同的错误消息。 – Lee

回答

0

的问题是在Ajax调用,具体数据:。$的toJSON(...)以下的部分,现在的代码工作完全

$.ajax({ 
         type: "POST", 
         url: "ReportIncident.aspx/GetIncidentsNearBy", 
         data:"{categoryId:" + categoryId+",latitude:"+latitude+",longitude:"+longitude+",dateTime:'"+dateTime+ "'}", 
         contentType: "application/json; charset=utf-8", 
         dataType: "json", 
         success: function (msg) 
         { 
          console.log(msg.d);       
          $("#Result").text(msg.d); 
         } 
        }); 
相关问题