0

我已经弄清楚了大部分,但我想知道是否需要返回部分页面视图或仅返回图像。

因此,在 MVC 下需要实现下钻图表的方式可以参见:http: //geekswithblogs.net/DougLampe/archive/2011/01/23/charts-in-asp.net-mvc-2-with -drill-down.aspx

这里要说明的关键点是,我们正在利用一系列的 URL 属性来导航图表上的“下一级”。

public ActionResult HistoricalChartMap(int reportID)
{
    HistoricalChartData chartData = new HistoricalChartData(reportID, string.Format("Chart_{0}", Guid.NewGuid().ToString().Replace('-', 'a')));
    LineChart chart = new LineChart(chartData);

    foreach (Series series in chart.Series)
    {
        string postBackValue = series.PostBackValue;
        series.Url = string.Format("../Chart/HistoricalDrillDown?ReportID={0}&PostBackValue={1}", reportID, postBackValue);
    }

    //Must call SaveImage before GetHtmlImageMap
    var imgStream = new MemoryStream();
    chart.SaveImage(imgStream);
    imgStream.Seek(0, SeekOrigin.Begin);

    string sessionKey = string.Format("HistoricalReport: {0}", reportID);
    Session[sessionKey] = chart;

    // Return the contents of the Stream to the client
    return Content(chart.GetHtmlImageMap("HistoricalChartMap"));
}

请注意,URL 指向我的 ChartController 的一个方法:

public ActionResult HistoricalDrillDown(int reportID, string postBackValue)
{
    string sessionKey = string.Format("HistoricalReport: {0}", reportID);
    LineChart lineChart = (LineChart)Session[sessionKey];
    lineChart.DrillChart(postBackValue);

    var imgStream = new MemoryStream();
    lineChart.SaveImage(imgStream);
    imgStream.Seek(0, SeekOrigin.Begin);

    // Return the contents of the Stream to the client
    return File(imgStream, "image/png");
}

HistoricalDrillDown 返回我想在局部视图中显示的新 ChartImage,但此时我正在丢球。我应该如何用返回的图像替换我当前的图表图像?目前,我只是被定向到一个只有图表图像的新页面。

我的部分视图的标记是这样的:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div id="HistoricalChartDialog">
    <div id="ChartConfigurators">
        <label for="ReportSelector">Historical Chart: </label>
        <select id="ReportSelector" name="ReportSelector"></select>

        <div id="ToggleLegendWrapper">
            <label for="ToggleLegend">Toggle Legend</label>
            <input type="checkbox" id="ToggleLegend" name="ToggleLegend" />
        </div>
    </div>
    <img id="HistoricalChart" src="" alt="" usemap="#HistoricalChartMap" />
</div>

注意这个局部视图中间的 img 标签。在用户按照 URL 访问 HistoricalDrillDown 后,我想更新 img 的 SRC 属性。

采纳建议。:)

亲切的问候。

4

1 回答 1

0

我选择这样做:

foreach (Series series in lineChart.Series)
{
    series.Url = string.Format("javascript: DrillChart('{0}')", series.PostBackValue);
}

然后处理逻辑客户端以替换图像。

于 2012-01-18T17:36:58.873 回答