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()中的参数传递