我有一个动作来设置MS图表,然后将图像文件返回给AJAX调用。
这是我的动作
public FileResult MyAction(ICollection<MyModel> lstModel)
{
using (System.Web.UI.DataVisualization.Charting.Chart chart = new System.Web.UI.DataVisualization.Charting.Chart())
{
// Here is my code to set up points to the chart...
MemoryStream imageStream = new MemoryStream();
chart.SaveImage(imageStream, ChartImageFormat.Png);
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.SystemDefault;
return File(imageStream.GetBuffer(), @"image/png");
}
}
这是我的jquery AJAX调用
function ShowChart() {
var url = "/MyController/MyAction";
$.ajax({
url: url,
cache: false,
type: 'POST',
data: $("#myForm").serialize(),
success: function (data) {
$("#imgChart").attr("src", data);
}
});
}
但是图表未显示。谁能帮我吗?