gpt4 book ai didi

c# - 在 ASP.NET 中处理服务器端数据的 Javascript

转载 作者:太空宇宙 更新时间:2023-11-03 18:14:26 25 4
gpt4 key购买 nike

我有一个程序,它通过 c# 代码隐藏中的 linq-to-entities 查询从 sql db 获取位置列表。此列表需要通过 javascript 方法(Google maps api v3)进行解析,以便在 map 上显示位置。我需要找到从服务器端查询获取信息到 javascript 函数进行处理的最佳方法。有什么想法吗!?

编辑:序列化错误...

JavaScriptSerializer jss = new JavaScriptSerializer();
using (RamRideOpsEntities myEntities = new RamRideOpsEntities())
{
var validDates = (from a in myEntities.AdminOptions
select new { a.ValidDate1, a.ValidDate2 }).First();

var allWaitingRides = (from r in myEntities.Rides
where ((r.TimeOfCall >= validDates.ValidDate1 ||
r.TimeOfCall <= validDates.ValidDate2) && r.Status.Equals("Waiting", StringComparison.OrdinalIgnoreCase))
orderby r.TimeOfCall descending
select r).ToList();

json_topTen.Value = jss.Serialize(allWaitingRides.GetRange(0, 10).ToArray());
}
Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

Source Error:


Line 106: select r).ToList();
Line 107:
Line 108: json_topTen.Value = jss.Serialize(allWaitingRides.GetRange(0, 10).ToArray());
Line 109: }
Line 110: }

Source File: D:\DOCUMENTS\RamRide\RamRideOps_PL\RamRideOps\RamRideOps\Ops\DispatchCar.aspx.cs Line: 108

Stack Trace:


[ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
System.Collections.Generic.List`1.GetRange(Int32 index, Int32 count) +70
RamRideOps.DispatchCar.setTopTen() in D:\DOCUMENTS\RamRide\RamRideOps_PL\RamRideOps\RamRideOps\Ops\DispatchCar.aspx.cs:108
RamRideOps.DispatchCar.Page_Load(Object sender, EventArgs e) in D:\DOCUMENTS\RamRide\RamRideOps_PL\RamRideOps\RamRideOps\Ops\DispatchCar.aspx.cs:41
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

最佳答案

从 C# 导出数据的最简单方法可能不是在 JavaScript 中使用数据的最简单方法,但我将从后者的 Angular 对其进行尝试。

从 JavaScript 的 Angular 来看,最好的方法可能是将查询的内容导出为 JSON 表示,可能使用 JSONP。将其传输给客户端。您可以使用标准 XMLHttpRequest从您的服务器获取该数据,并从那里在客户端解析它以在 JS 中使用。

本站JSON.org有一个 C# 中可用的许多 JSON 解析器/序列化器的列表。

关于c# - 在 ASP.NET 中处理服务器端数据的 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8949046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com