I have an action method that in the view part I Use Json to get data from other action in my controller , it go to success method when i call it directly , (put routConfig action eqaul to this Action )
我有一个动作方法,在视图部分我使用Json从我的控制器中的其他动作获取数据,当我直接调用它时,它转到成功方法,(将routConfig动作eqaul放到此Action)
but when i call the action from links it goes to error , I dont know why ?!
但是当我从链接调用动作时它会出错,我不知道为什么?!
Controller:
[HttpGet]
public ActionResult PieRenderer()
{
return View();
}
[HttpPost]
public JsonResult GetPieRenderer()
{
var DbResult = from d in db.Rep_TaskTypeQueuChart(0, 1)
select new
{
d.TaskTypeName,
d.WorkCount
};
//return Json(DbResult, JsonRequestBehavior.AllowGet);
return Json(DbResult);
}
view:
<!-- CSS -->
<link href="~/Scripts/jqPlot/jquery.jqplot.min.css" rel="stylesheet" />
<!-- Scripts JS -->
<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<script src="~/Scripts/jqPlot/jquery.jqplot.min.js"></script>
<script src="~/Scripts/jqPlot/plugins/jqplot.pieRenderer.js"></script>
<script>
$.jqplot('chartdiv', [[[1, 2], [3, 5.12], [5, 13.1], [7, 33.6], [9, 85.9], [11, 219.9]]]);
$(document).ready(function () {
// $.jqplot('chartdiv3', [[[1, 2], [3, 5.12], [5, 13.1], [7, 33.6], [9, 85.9], [11, 219.9]]]);
//$.ajax(alert('Hiiiiiiiii')); //alert('111')
$.ajax({
type: "POST",
url: "Cartable/GetPieRenderer",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
function OnSuccess(response) {
var aData = response;
var dataArray = [];
$.each(aData, function (i, item) {
dataArray.push([item.TaskTypeName, item.WorkCount]);
alert(item.TaskTypeName);
});
var plot1 = jQuery.jqplot('chartdiv3', [dataArray],
{
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
sliceMargin: 4,
// Put data labels on the pie slices.
showDataLabels: true
}
},
legend: { show: true, location: 'e' }
}
);
}
function OnError(response) {
alert("Error !");
alert(response.toString());
}
});
</script>
</div>
If I change RoutConfig action="PieRenderer" it shows the result. but if i run the main dashboard view , and there i had a actinlink or a href to PieRenderer method , it goes to error method ()...
如果我更改RoutConfig action =“PieRenderer”,它会显示结果。但是,如果我运行主仪表板视图,并且我有一个actinlink或一个href到PieRenderer方法,它会转到错误方法()...
1 个解决方案
#1
0
I Find the answer , the problem because of this part : url: "Cartable/GetPieRenderer"
我找到答案,问题因为这部分:url:“Cartable / GetPieRenderer”
it should be change like this : url: "/Cartable/GetPieRenderer",
它应该像这样改变:url:“/ Cartable / GetPieRenderer”,
#1
0
I Find the answer , the problem because of this part : url: "Cartable/GetPieRenderer"
我找到答案,问题因为这部分:url:“Cartable / GetPieRenderer”
it should be change like this : url: "/Cartable/GetPieRenderer",
它应该像这样改变:url:“/ Cartable / GetPieRenderer”,