Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何渲染从控制器传递到Razor视图的图像';作为文件的操作方法?_Html_Asp.net Mvc_Razor_Charts_Asp.net Mvc 5.1 - Fatal编程技术网

Html 如何渲染从控制器传递到Razor视图的图像';作为文件的操作方法?

Html 如何渲染从控制器传递到Razor视图的图像';作为文件的操作方法?,html,asp.net-mvc,razor,charts,asp.net-mvc-5.1,Html,Asp.net Mvc,Razor,Charts,Asp.net Mvc 5.1,我有一个控制器操作方法,它返回一个包含图像和图表的文件: public ActionResult EfficiencyChart(string id) { var myChart = new Chart(width: 600, height: 400) .AddTitle("Chart Title") .AddSeries( name: "Employee", xValue: new[] { "Peter", "Andrew", "Juli

我有一个控制器操作方法,它返回一个包含图像和图表的文件:

public ActionResult EfficiencyChart(string id) {
    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();

    myChart.Save("~/Content/chart", "jpeg");
    // Return the contents of the Stream to the client
    return base.File("~/Content/chart", "jpeg");        
}

如何在
EfficiencyChart.cshtml
中呈现它?

在您的EfficiencyChart.cshtml中,使用带有
Url.Action()的简单图像标记
-

<img src="@Url.Action("ActionName","ControllerName",new { id = PassYourIDHere  })" />


我不应该使用任何模型吗?我没有收到你的评论,你能详细说明一下吗?我正在返回一个
ActionEvent
(一个文件)。该
ActionEvent
是否会作为模型传递给视图?PS:它起作用了。在EfficiencyChart.cshtml(您使用的任何模型)中,让它包含一个属性调用Id,然后将其作为Url.Action()中的参数传递