Can't build a chart with razor when using partial view as image src

前端 未结 1 346
無奈伤痛
無奈伤痛 2021-01-26 14:54

How can I make chart in view with razor? Tried to use partial view (_Chart.cshtml):

@{
    var usdChart = new Chart(width: 600, height: 400)
    .AddTit         


        
1条回答
  •  -上瘾入骨i
    2021-01-26 15:29

    With your current code, it will not render the image in the main view. Instead it render just the image. It is because when you make the partial view call, the Chart.Write method will convert the chart object to a jpg and write to the output stream.

    You should create an action method which returns this partial view result and use that as the image src attribute value

    public ActionResult Chart()
    {
        return PartialView("_Chart");
    }
    

    and in the main view

    
    

    When the page loads, it will make a separate http call to the image source url which returns just the image

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