Showing System.Web.Helpers.Chart in a partial view from the model

前端 未结 2 1565
死守一世寂寞
死守一世寂寞 2020-12-10 08:19

So I was trying out the Chart helpers in the System.Web.Helpers namespace.

according to http://www.asp.net/web-pages/tutorials/data/7-displaying-data-in-a-chart

相关标签:
2条回答
  • 2020-12-10 09:11
    <div>
        <h2>Some header above a graph</h2>
        <img src="@Url.Action("DrawChart")" />
    </div>
    

    and then you could have a controller action:

    public ActionResult DrawChart()
    {
        MyViewModel model = ...
        return View(model);
    }
    

    and a corresponding view that will draw the chart (DrawChart.cshtml):

    @model MyViewModel
    
    @{
        // TODO: use the data from the model to draw a chart
    
        var myChart = new Chart(width: 600, height: 400)
            .AddTitle("Chart Title")
            .AddSeries(
                name: "Employee",
                xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" },
                yValues: new[] { "2", "6", "4", "5", "3" })
            .Write();
    }
    

    and the rendered result:


    enter image description here

    0 讨论(0)
  • 2020-12-10 09:13
    <div>
    <h2>Some header above a graph</h2>
    <img src="@Url.Action("DrawChart")" />
    </div>
    
    public ActionResult DrawChart()
    {
    MyViewModel model = ...
    return View(model);  
    
    }
    

    !!! To send the Model parameter to DrawChart

    Change to

    <div>
        <h2>Some header above a graph</h2>
        <img src="@Url.Action("DrawChart",Model)" />
    </div>
    
    public ActionResult DrawChart(MyViewModel _MyViewModel )
    {
        MyViewModel model = MyViewModel ;
        return View(model);
    }
    

    MyViewModel is Null

    Seek advice from those who know.

    0 讨论(0)
提交回复
热议问题