在HighChart中,我需要绘制一系列针对x和y轴的数据.HighChart希望数据采用json格式.即,[[x,y],[x,y] ...... [x,y]].其中x和y是时间(1392345000 - Unix纪元格式)和值(49.322).所以我正在进行ajax调用以获取数据,并且在成功时我将json返回的数据呈现在highchart中.在大多数情况下,即,如果数据计数([x,y])低于87500行,则Json将数据从控制器返回到视图.但是当数据超过87500时,使用404调用ajax错误,未找到错误.json返回的数据是否有任何大小限制.
public JsonResult GetPlotData(Dictionary<string, List<ChartData>> dataPlot)
{
// dataPlot = D00213 - [[13245678000,49.9],[13245345000,43.9]...[n,n]]
// if dataPlot.Count < 87500 here throwing error and in ajax error 404 Not found
return Json(dataPlot, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
$.ajax(
{
url: '../Report/GetPlotData',
data: { "fromDate": fromDate, "toDate":toDate, "item": items[i].id },
type: "POST",
dataType: "json",
cache: false,
success: function(chartData) {
alert(‘success’
},
error: function(xhr, ajaxOptions, thrownError)
{
debugger;
ShowDialogError(xhr, 'Site Status Report');
}
});
Run Code Online (Sandbox Code Playgroud) 我需要显示Json返回的消息.
在控制器中,抛出异常并捕获到catch块中.我正在返回错误错误消息.
在Ajax中,成功部分始终执行.但如果是从我的错误web服务,我不想执行正常; 相反,我想显示一条错误消息.
我怎么能做到这一点?
我的代码如下:
[HttpPost]
public JsonResult DeleteClientRecord()
{
bool result = true;
try
{
result = ClientCRUDCollection.DeleteClient(deleteClientId);
}
catch (Exception ex)
{
return Json(ex.Message, JsonRequestBehavior.AllowGet);
}
return Json(new { result }, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
$("#YesDelete").click(function () {
$.ajax({
type: "POST",
async: false,
url: "/Client/DeleteClientRecord",
dataType: "json",
error: function (request) {
alert(request.responseText);
event.preventDefault();
},
success: function (result) {
// if error from webservice I want to differentiate here somehow …Run Code Online (Sandbox Code Playgroud) 我目前正在研究VS2010-SP1中的MVC4.我在控制器类Asynchronous中创建了一个函数.作为其中的一部分,我创建了从AsyncController派生的控制器类,并添加了以下两个方法(请参阅下面的代码部分1和2).一个以Async结尾的方法(参见代码第1节)和另一个以Completed结尾的方法(参见代码第2节).问题出在模型类中我试图使用来自HttpContext的凭据访问我的web服务(参见下面的代码3).进行异步调用时,上下文为空.即,在新的线程中,httpcontext不可用.如何将上下文从主线程传递到创建的新线程.
代码第1节
public void SendPlotDataNewAsync(string fromDate, string toDate, string item)
{
AsyncManager.OutstandingOperations.Increment();
var highChartModel = new HighChartViewModel();
Task.Factory.StartNew(() =>
{
AsyncManager.Parameters["dataPlot"] =
highChartModel.GetGraphPlotPointsNew(fromDate, toDate, item);
AsyncManager.OutstandingOperations.Decrement();
});
}
Run Code Online (Sandbox Code Playgroud)
第2节
public JsonResult SendPlotDataNewCompleted(Dictionary<string, List<ChartData>>
dataPlot)
{
return Json(new { Data = dataPlot });
}
Run Code Online (Sandbox Code Playgroud)
第3节
public List<MeterReportData> GetMeterDataPointReading(MeterReadingRequestDto
meterPlotData)
{
var client = WcfClient.OpenWebServiceConnection<ReportReadingClient,
IReportReading>(null, (string)HttpContext.Current.Session["WebserviceCredentials"] ??
string.Empty);
try
{
return
ReadReportMapper.MeterReportReadMap(client.GetMeterDataPointReading(meterPlotData));
}
catch (Exception ex)
{
Log.Error("MetaData Exception:{0},{1},{2},{3}",
ex.GetType().ToString(), ex.Message, (ex.InnerException != null) ?
ex.InnerException.Message : String.Empty, " ");
throw; …Run Code Online (Sandbox Code Playgroud)